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
357
Reaction score
269
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
656
Reaction score
368
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

What is a thing you like to see in RPGs?
Well, I hope things go well tomorrow. I think I might be coming down with a cold, so gonna warm up some chicken soup and sleep.
Status too sad. Pls delete, mods. Thanks.
The most important thing to design your game for is fun. If a game isn't fun, why would anyone want to play it? Well, that and "can you play the game?". Anything else is incidental.
I just realized that I have been on this site for nearly 1/3 of my life...

Forum statistics

Threads
124,678
Messages
1,165,188
Members
163,488
Latest member
williswhere
Top