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
354
Reaction score
266
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 Posts

Latest Profile Posts

I may or may not be slightly crazy. Since I couldn’t find anything to renumber generator parts files that works on Linux, I’m scripting something up to run via terminal that’ll do the job. (Face is done (and was a fustercluck-and-a-half), and I’m taking a well-earned break before tackling SV, TV, TVD, and Variation. @.@)
I fixed my little itch.io issue... apparently filenames are case-sensitive. After I renamed the file IconSet.png instead of Iconset.png, it worked. I changed it back and forth a few times just to confirm this.

I'm gonna go beat my head against the wall now.

and an original idea of people having alter egos is back... finally.
Another camping area.
I just found out somebody pirated my 3,99$ game. I spent over a year making it and somebody just publish it for free a week after early access released.

I should be glad, cuz if they pirate you, that means your game has to be good, but im not. I barely sold any copy. Didn't get any info from most of the sites I wrote.

Forum statistics

Threads
124,642
Messages
1,164,924
Members
163,466
Latest member
nnl94
Top