I'm trying to multiply a variable by a certian percent, specificly 5%, but there seems to be no way to use percentages with variables, at least without a script. Is there any way to do this?
How to multiply a Variable by a percent?
RPG Maker MV Supportinstead of multiplying by the percentage, you can multiply by the percentage * 100 and then divide the 100 back out in the end. so if you wanted 5% of 200 as an example, you can multiply 200 by 5 instead of .05 and then divide the 1000 by 100 to get 10.
its worth noting that one of the behaviors of the control variables event command is to round any number it writes into a variable so that theyre always integers. you can bypass that with script, but i dont think you can avoid that without it.
its worth noting that one of the behaviors of the control variables event command is to round any number it writes into a variable so that theyre always integers. you can bypass that with script, but i dont think you can avoid that without it.
JavaScript:
$gameVariables(x) * (100 / .05)
Edit #2 because I can't do simple things:
I'm dumb. It's fine. You'd actually need something like this:
JavaScript:
$gameVariables.value(x) * .05
Er, 100 / 0.05 is 2000. I'm not sure you want to multiply the number by 2000. 😛
If you want 5% of a variable, just multiply it by 0.05.
So basically:
$gameVariables(x) * (/ 0.05) ?
If you specifically always want 5% of a number, you can just divide it by 20.
(Of course, if rounding is an issue you might not be able to do it this way, so it depends what numbers you'll be using).
(Of course, if rounding is an issue you might not be able to do it this way, so it depends what numbers you'll be using).
Something like this, using 1 as an example
Code:
$gameVariables.setValue(1, $gameVariables.value(1) * 0.05);
It was late. That was admittedly stupid. You are correct, that equation is wildly inaccurate :oops: Edited the original equation :oops:
I hate to be that guy but your equation still doesn't work because $gameVariables(x) doesn't do anything; it has to be $gameVariables.value(x)
No, please be that guy lol. I'll never be offended if I'm corrected. I haven't been in the editor lately as I've been working in Google Docs. It's so simple and I don't want to spread misinformation. Reedited.
Original thread: https://forums.rpgmakerweb.com/threads/how-to-multiply-a-variable-by-a-percent.177154/