random roll between 1 and [variable]?

Hello everyone
In my game, I want to use a dialogue system that depends on character's affection.
I want the game to roll randomly between 1 and [affection variable], then adding a conditional to each affection tier.
For example, if you have 2 affection value towards the character, there's no chance to hear the "level 5 affection dialogue" when the game rolls for the random dialogues.
So the more affection you have, the morie dialogue you can get. (please don't question the design choice of this, it works in the context of the game)
ANYWAY, in control variable you can only put numbers in the two values of "random".
Can anyone help me? Is there a script I can use instead? Tried to look for it in the internet but I didn't find anything.
You were already given this code in one of your prior threads.


1713718014268.png


So if you want the value to be between 1 and the variable, you'd just add 1 to the result.

Tried to look for it in the internet but I didn't find anything.
I Googled "RPG Maker MZ script random" and several threads with this code come right up 😉 It should also be in the pinned thread of MZ Script Calls.
You were already given this code in one of your prior threads.


View attachment 302554

So if you want the value to be between 1 and the variable, you'd just add 1 to the result.


I Googled "RPG Maker MZ script random" and several threads with this code come right up 😉 It should also be in the pinned thread of MZ Script Calls.
thanks for your answer and sorry for the question but where is the result of the script is stored?
thanks for your answer and sorry for the question but where is the result of the script is stored?
It's not stored anywhere in this example - this is just an expression that will have a random value, it can be used for anything. To store it in variable simply use a command to set the value of a variable to a script, and put that expression in there.

Or run a script command, and do (if you want to store it in variable 42):
$gameVariables.setValue(42, Math.randomInt($gameVariables.value(19)));
where is the result of the script is stored?
You said in your first post
in control variable
so it's stored in whichever variable you select in that drop-down box.

1713730187205.png
You said in your first post

so it's stored in whichever variable you select in that drop-down box.

View attachment 302586
OHHHHHHHH *mind blown* NOW I get it. Tried and it works as intended. Thank you so much!

Original thread: https://forums.rpgmakerweb.com/threads/random-roll-between-1-and-variable.167950/