Multiple Progress Bars Linked Together - Math Help

I have four progress bars each defining a different emotion. There are circumstances that change each emotion.

Love = 0.25
Order = 0.25
Chaos = 0.25
Hate = 0.25

If I increment by a value of one to love… you divide that value by 3 (for the unincremented bars) and subtract that from the bars not being incremented. My issue is that I can’t wrap my head around the math right. If any one of the three bars getting subtracted from = 0 already, you would not divide by three… but rather 2… and if only two bars are > 0 then you would just subtract from 1.

Can someone help clear my head a little bit and show me how to do this? I feel like a newb for asking lol.

Guy, I‘m not able to follow your train of thoughts but I also use progress bars and as far as I know it is like that, that
not filled=0 COMPLETELY filled = 1. if your value you are binding your progress bar to is above 1 say 2, then it will stay full the same way as if it was 1.5 only. So take your math and think cause I‘m currently sitting here and learning for my physics exam. Maybe I could help, maybe not.

When you do the division you could add together the total number of bars that are above 0 remembering to exclude the one you are adding to. Then use the result of that as your divisor.

You definitely misunderstood. I know that the bar starts at zero to one. You can multiply this value by 100 to get actual percent and then divide by 100 again for the float value. Now if you had 4 progress bars that collectively equal 1.0 then what would the math be when you move one individually and how would that value be mapped to the remaining three? Now read my question again…

This was how I was doing it, but the problem I run into is that if I have one value drastically greater then all the other values and all values are greater than 0… and I increment the smallest value… the largest value is not decremented with the proper aspect ratio and the whole thing becomes offset.

If the bars are working properly except for being off by 1 here or there in some edge cases, you’re probably running into floating-point accuracy errors.

I would suggest separating your display values (held in the progress bars) from your logic values. Store the values and perform your logic at a scale that makes sense for your game and maintains consistency (e.g. 1000 total points for all emotions, or 100 points for all emotions; appropriate numbers really depend on the granularity of your system and the rules you use to allocate points), or perhaps even keep the logic as integers.

Once you’ve got the data correct, convert the values to 0.0-1.0f and update the progress bars.

I have this working as intended here. I used a slider to set the value of the manually-changing progress bar with a float variable saving its previous value so the difference can be calculated. Once the difference is determined, that can be split between the three other bars to affect their values. In the case of one of the bars dropping below 0, the negative value is split between the remaining bars again, so the total remains 1. As noted in the image, as the main progress value approaches 1, the divided float’s rounded decimal places will rebound off each other, creating an infinite loop, so I blocked the value from getting too close to 1 without being exactly 1.

This is only working with user access to one of the bars, but of course an event could be made for each bar to allow for them all to be altered manually. The only things that would need to change are:

  • Each bar would need its own float variable
  • The bar percentage set by the event would need to match the current bar
  • The progress bars that make up the array would need to exclude the current bar and include the others

I’m probably too late for morglion, but being able to do this is really convenient if anyone else is trying this.