0

Hello I'm having trouble with a slider/bar in a game I'm developing. Basically, that bar is used to set the value of gold and depending on how much gold, a list of random chances to get a better item will come out (kinda like gacha). The problem is whenever I slide the bar to quickly, the list of random chances become faulty and show the incorrect values.

The video below might help showcase what my problem is: https://youtu.be/fGTomapSFk0

Here is the code of the bar. Please note that this is made with the renpy game engine.

screen tailor_hud():
    
    tag second

    add "gui/main_hud/tailor_hud.jpg" xoffset glist_posX yoffset glist_posY+62

    bar:
        xoffset glist_posX+32
        yoffset glist_posY+560
        base_bar "gui/bar/shop_price.png"
        thumb "gui/bar/mini_thumb.png"
        thumb_offset 7
        xysize (380, 30)
        left_gutter 10
        right_gutter 22
        value VariableValue("INVESTMENT", 4650, offset=350, action=(Function(update_custom)), step=50, force_step=True)

    text str(INVESTMENT) xoffset glist_posX+178 yoffset glist_posY+528 size 21 font "font/maian.ttf" color gold_color

    vbox:
        for txt in DISPLAY_PERCENTAGES:
            textbutton str(txt):
                action NullAction()
        xalign 0.3
        yalign 0.5

And here is the code underlying the gold or INVESTMENT:

    def update_custom():

        avail_qualities = []

        for key, value in APPAREL_MIN_MAX.items():
            min_value = value[0]
            max_value = value[1]
            if INVESTMENT >= min_value and INVESTMENT <= max_value:
                avail_qualities.append(key)

        custom_order_weights = []

        min_val_list = [tup[0] for tup in APPAREL_MIN_MAX.values()]
        max_val_list = [tup[1] for tup in APPAREL_MIN_MAX.values()]

        idx = QUALITY_TO_INDEX[avail_qualities[0]]
        count = 0
        while count < len(avail_qualities):
            qual_min_weight = INVESTMENT - min_val_list[idx]
            qual_max_weight = INVESTMENT - max_val_list[idx]
            idx += 1
            count += 1
            
            qweight = min([qual_min_weight, abs(qual_max_weight)])
            custom_order_weights.append(qweight)

        possible_percentages = []

        for weight in custom_order_weights:
            percent = (weight/(sum(custom_order_weights)))*100
            possible_percentages.append(percent)

        idx = 0
        for quality in avail_qualities:
            DISPLAY_PERCENTAGES[QUALITY_TO_INDEX.get(quality)] = round(possible_percentages[idx], 2)
            idx += 1

I'm kind of new to programming so any advice is appreciated.

Deimos96
  • 13
  • 3

0 Answers0