MZ Any way to have a conditional event choose between a range of numbers in a variable?

Just wondering if there's a way to have the conditional event command to pick between a range of numbers in a variable.

1. First a variable picks a random number between 1 and 20.
2. A conditional event then has different outcomes depending on the number. 1 - 10 fails, which is easy enough to implement, simply being lesser or equal to 10.
3. A different outcome would happen between numbers 11 - 15
4. And then another outcome for 15 -20. This one is also easy just being greater or equal to.

I'm having questions about the 3rd step. Do I have to use the approach using a separate conditional event for each number, or is there a procedure in Rpg Maker MZ where you can tell it to apply a condition within a range like this. (If it's 11 to 15, then do this...)
I think you can use the Script option (Page 4) in Conditional Branch, and state your condition there like:

Code:
$gameVariables.value(x) >= 11 && $gameVariables.value(x) <= 15

Which X is the variable ID from the variable you set before
a cleaner way is to do make conditions separate or nested.


Code:
// sample 1

if variable x > 0 && variable x <= 10
outcome 1
end

if variable x > 10 && variable x <= 15
outcome 2
end

if variable x > 15
outcome 3
end

// alternate
if variable x < 11
outcome 1
else
if variable x < 15
outcome 2
else
if variable < 20
outcome 3
end
end
end

those are valid ways to use 1 variable.

this is the pure evented way, but you can make it shorter as well,
which require ternary operator to get a sweet 1 liner or under each other
to make it more readable, but also cleaner to write.

but that choice is up to you though.
Hey thanks for the script, it works perfectly. This is going to be used for a way to acquire magic in battle but with a chance of gaining a variety of types - and a good chance of failure.

Thanks for the quick reply. 🙂

Cheers
I think you can use the Script option (Page 4) in Conditional Branch, and state your condition there like:

Code:
$gameVariables.value(x) >= 11 && $gameVariables.value(x) <= 15

Which X is the variable ID from the variable you set before

Original thread: https://forums.rpgmakerweb.com/threads/any-way-to-have-a-conditional-event-choose-between-a-range-of-numbers-in-a-variable.180332/