Set a Variable's value to a random number from 0 to the value of another Variable

Newquaza 96

Veteran The question is basically all in the title, but i will explain the context in case there's a better way to do this that i am overlooking.
For my project, i am using stat checks to determine the outcome of certain events:
For example, when a boulder blocks the path, the player will have to choose one of the actors to try and move said boulder
Choosing an actor makes it so the Variable "Calc1" is set to the selected actor's Strength, while the Variable "Calc2" is set to the selected actor's Level+5.
Then, i would change the variable "Random1"'s value to a random number between 0 and the value of the variable "Calc2".
Afterwards, i would have the game check whether the value of the variable "Random1" is smaller than or equal to the value of variable "Calc1".
If Random1 is smaller than or equal to Calc1, then the check is a success. Otherwise, it is a failure.
I tried calling the following script to change the value of variable 1 (Random1) to a number from 0 to the value of variable 16 (Calc2), but it doesn't work.
\$gameVariables.setValue(1, Math.random(\$gameVariables.Value(16)));

Rukiri

I like to make Action-RPGs I'm going to say your variable ids are 1 and 2 for this example.
Code:
function random_range(min, max) {
return Math.random() * (max - min) + min;
}
\$game_variables = random_range(\$game_variables, \$game_variables);
if (\$game_variables <= \$game_variables) {
//success
} else {
//failure
}

Verdelite

Wannabe Developer I'm not entirely sure since I'm not familiar with RMMV's functions yet, but afaik Math.random() returns a decimal, and I think it has to be
\$gameVariables.value(id) with a lowercase 'v'
Try using
\$gameVariables.setValue(1, Math.randomInt(\$gameVariables.value(16)));

Feel free to correct me if I'm wrong, am noob • Newquaza 96

Newquaza 96

Veteran I'm not entirely sure since I'm not familiar with RMMV's functions yet, but afaik Math.random() returns a decimal, and I think it has to be
\$gameVariables.value(id) with a lowercase 'v'
Try using

Feel free to correct me if I'm wrong, am noob This actually works! I suppose it was just a matter of small things after all. Thank y'all very much for your help, i greatly appreciate it.

• Verdelite

Latest Profile Posts

Ugh, can't decide what to make next!
The Dystopia Recently got RPG Maker MZ. A bit slower with my current PC but I will be getting a new one soon.
evening progress; pretty happy where this is at so i'll take the rest of the night to myself =w= It would seem learning JS is not a know it all for making plugins. While it has enabled me to understand what I'm looking at, I still have to find the relevant information in the core scripts. This is much harder than learning JS IMO.