hananack

Villager
Member
Joined
Jun 19, 2022
Messages
11
Reaction score
6
First Language
Hebrew
Primarily Uses
RMMZ
howdee.
how do i set a variable to be random between 1 to another variable
thank you
 

Jragyn

JABS codemonkey
Veteran
Joined
Aug 14, 2012
Messages
353
Reaction score
265
First Language
English
Primarily Uses
RMMZ
Untested, but I think using the script section of the "control variables" command, you could do something like:
JavaScript:
Math.randomInt(1, $gameVariables.value(VARIABLE_ID));
// where VARIABLE_ID is the id of the variable you're looking to use as an upper limit.

Math.randomInt(min, max) is an extension method provided by RMMZ's core codebase, but I'm not 100% sure if it is usable in script commands and the like.
 

hananack

Villager
Member
Joined
Jun 19, 2022
Messages
11
Reaction score
6
First Language
Hebrew
Primarily Uses
RMMZ
no it didnt work it gives me the value of 0

but
Math.randomInt($gameVariables.value(VARIABLE_ID)+1)
gave me the result i needed

Thank you
 
Last edited:

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
655
Reaction score
366
First Language
German
Primarily Uses
no it didnt work it gives me the value of 0

but
Math.randomInt($gameVariables.value(VARIABLE_ID)+1)
gave me the result i needed

Thank you
Only a small correction:
Math.randomInt(X) gives you a number between 0 and X-1, so you should add 1 to the result if you want a value between 1 and X:

1 + Math.randomInt($gameVariables.value(VARIABLE_ID))
 

Latest Threads

Latest Profile Posts

I finally finished the Coliseum for my game. Love how it looks. Credits for the assets goes to Kokoro Reflections, @Starbird_Resources, and @megumi014.
Colossuem.png
Mimics! Mimics everywhere!
Pirate portrait quickie :LZYcheeze:
pirate.png
My game has a (much needed) tutorial now...
Game Making Every Day #20:kaohi:

Forum statistics

Threads
124,511
Messages
1,164,157
Members
163,346
Latest member
LightTenko
Top