Hello! I' m trying to multiply a variable by a number between x and y with a scrpt. Let's say x = 50 and y = 200. I tried with this one:
$gameParty.gainGold($gameVariables.value(52) * >= 50 && <= 200);
but is not working. Any ideas?
Try this
$gameParty.gainGold($gameVariables.value(52) * (Math.floor(Math.random() * 151) + 50))
It works! Thanks! However, as I have to repeat this process with other values, I would like to understand the math behind that formula. I mean, what should I do if I want to change the values? Why 151?
Math.random() gives you a random decimal number between 0 inclusive and 1 exclusive or 0<=x<1.
(Math.random() * 151) gives you a random decimal number between 0 inclusive and 151 exclusive or 0<=x<151, so 0 to 150.
Math.floor will floor the result or round it down so it's an integer/whole number.
+50 will add 50 to the result and ensure a minimum value of 50.
So your result is a random integer/whole number between 50 and 200 inclusive.
Ohh! I undestood! You're great. Thank you so much.