MV Dice roll script question

Hello. I read in these forums about a dice roll script to generate a random integer between 1 and 10 is Math.randomInt(10) + 1

What if I also want to add "if 'x' is ≥ 7 then Conditional Branch option 1" and "if 'x' is < 7 then Conditional Branch option 2" ?

It will be on an event that occurs when the player presses a button on that event.
Hi!

Script call​

You could use something like this in Conditional Branch -> Script:
JavaScript:
Math.randomInt(10) + 1 >= 7
I.e. "true iff random roll (1~10 inclusive) is 7 or more". Then check the "Create Else Branch" option for the other case.

branch-else.png

Alternative​

However, I would suggest using a variable here instead. The Control Variables command lets you change the value of a variable, and has an option for "Random". A variable is just like a box that stores a value: Control Variables is how you change what is stored in these boxes.

So you could store the value and then check it without needing any script calls, e.g.
  • Control Variables: {0006: Random Roll} -> Set -> Random: 1 ~ 10
    Spoiler: screenshot
    controlvariables.png
  • Conditional Branch -> Variable {0006: Random Roll} ≥ 7
This would also mean that the rolled value is stored for any further checks, e.g. if you want 3+ different outcomes, or for displaying the rolled value using \v[6] in a Show Text command.
Hi!

Script call​

You could use something like this in Conditional Branch -> Script:
JavaScript:
Math.randomInt(10) + 1 >= 7
I.e. "true iff random roll (1~10 inclusive) is 7 or more". Then check the "Create Else Branch" option for the other case.

View attachment 343161

Alternative​

However, I would suggest using a variable here instead. The Control Variables command lets you change the value of a variable, and has an option for "Random". A variable is just like a box that stores a value: Control Variables is how you change what is stored in these boxes.

So you could store the value and then check it without needing any script calls, e.g.
  • Control Variables: {0006: Random Roll} -> Set -> Random: 1 ~ 10
    Spoiler: screenshot
  • Conditional Branch -> Variable {0006: Random Roll} ≥ 7
This would also mean that the rolled value is stored for any further checks, e.g. if you want 3+ different outcomes, or for displaying the rolled value using \v[6] in a Show Text command.
Thank you so much and I will try it!
You're welcome, hope you get it working!

Original thread: https://forums.rpgmakerweb.com/threads/dice-roll-script-question.178398/