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
351
Reaction score
263
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
651
Reaction score
362
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 just got all of my wisdom teeth out today, thankfully I have the rest of the week off.
Man I am learning I am bad at naming armor lmao.
The game's opening, now fully polished! :LZScheeze:





Aaand, here's me working on it in today's "Game Making Every Day" video! :LZSooo:

Hello! Can anyone help me? I followed making cooking tutorial for RPG Maker MV. But for some reason buff state that food gives doesn't work in overworld. It disappears. What am I supposed to do?
A shotgun is not a rifle. Huh.

Forum statistics

Threads
124,408
Messages
1,163,396
Members
163,206
Latest member
mooly
Top