Linear Progress Help

I’m creating an XP level system that we see in games. To reach level 2 from level 1, the user must score 1000 points. I have used a linear progress bar and set the maximum value to 1000. Now when the user will score some points, it will increment the value by the number of the user’s score. Now the max value of progress bar to reach level 2 is 1000, so if the user scored more than 1000 points, I want to upgrade his level from 1 to 2 and the extra score which is left to add should get added in level 2 value.
Example: The user’s score is 1100, so his level is upgraded. Now I want to add the remaining score which is 100 to level 2 in progress bar. So for level 2, the maximum value of linear progress will be 2000 and it should increment the value of progress bar by the extra scored value which is 100. But how can I know how much he scored extra, so that I can increment the value of progress by the extra scored value?

If you subtract the total XP with the maximum value of the bar, you can get extra scores.

Let’s suppose the total XP is 2400,
and you set the Linear Progress bar’s maximum to 2000,
you can get “400” by subtracting maximum value with total XP.

2400 - LinearProgressBar.Maximum = 400


However as user can pass multiple levels at once, you should check the if earned XP is bigger than maximum XP in loop.

For example:

while userXP > LinearProgressBar.Maximum
      LinearProgressBar.Value = userXP - LinearProgressBar.Maximum
      LinearProgressBar.Maximum = LinearProgressBar.Maximum + 1000
      level = LinearProgressBar.Maximum / 1000

Hope this helps!

3 Likes

Yes. This was a simple math logic :stuck_out_tongue:
Anyway, it’s working now. Thanks brother!

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.