How do I calculate the current value of a variable as a percentage ? Let's say I have Variable 1 that is set to 999 and slowly decreases by 1 over time until it reaches 0, I want Variable 2 to reflect the current value of Variable 1 as a percentage of that base 999, so for instance when the first drops to 99 it would be the other as 10
MZ Calculate variable as a percentage
RPG Maker MZ SupportcurrentValue * 100 / maxValue
So, 99 * 100 / 999 = ~10%.
So, 99 * 100 / 999 = ~10%.
Also, make sure to multiply first (scale up), then divide (scale down), e.g.
Otherwise you'll lose precision because the result gets floored to an integer after each operation.
◆Control Variables:#0006 Percents = Current
◆Control Variables:#0006 Percents *= 100
◆Control Variables:#0006 Percents /= 999Otherwise you'll lose precision because the result gets floored to an integer after each operation.
Original thread: https://forums.rpgmakerweb.com/threads/calculate-variable-as-a-percentage.179246/