MZ [Help] How to check: variable 1 is greater than multiple variables( 2, 3, 4, 5)

Hi guys!
I want to put a condition where 1 variable is greater than others at once...
something like $gameVariable.values >=== variable 1, 2 , 3 ,4...
This is might be surprisingly simple within an event, it just means nesting your conditionals.

Spoiler: if A > B, C, D, E
nestedif.png
This is might be surprisingly simple within an event, it just means nesting your conditionals.

Spoiler: if A > B, C, D, E
I know that, but i want something more short, because are many variables
A couple more examples without scripting (if/else):
Spoiler: switch
◆Control Switches:#0022 temporary = OFF ◆If:test 1 ≥ test 2 ◆If:test 1 ≥ test 3 ◆If:test 1 ≥ test 4 ◆Control Switches:#0022 temporary = ON ◆ :End ◆ :End ◆ :End ◆If:temporary is ON ◆Comment:Condition met! Do stuff here. ◆ :Else ◆Comment:Condition not met. ◆ :End
Spoiler: exit event processing
◆If:test 1 ≥ test 2 ◆If:test 1 ≥ test 3 ◆If:test 1 ≥ test 4 ◆Comment:Condition met! Do stuff here. ◆Exit Event Processing ◆ :End ◆ :End ◆ :End ◆Comment:Condition not met.
Otherwise you could try something like this in Conditional Branch -> Script:
JavaScript:
const v = $gameVariables.value(1); [2,3,4,5].every(id => v >= $gameVariables.value(id))
I.e. "true iff the values of game variables 2, 3, 4, and 5 are all < the value of game variable 1". Technical details here:
[Edit: replaced var with const just because.]
[Edit 2: updated description to match script call. 😴]
A couple more examples without scripting (if/else):
Spoiler: switch
◆Control Switches:#0022 temporary = OFF ◆If:test 1 ≥ test 2 ◆If:test 1 ≥ test 3 ◆If:test 1 ≥ test 4 ◆Control Switches:#0022 temporary = ON ◆ :End ◆ :End ◆ :End ◆If:temporary is ON ◆Comment:Condition met! Do stuff here. ◆ :Else ◆Comment:Condition not met. ◆ :End
Spoiler: exit event processing
◆If:test 1 ≥ test 2 ◆If:test 1 ≥ test 3 ◆If:test 1 ≥ test 4 ◆Comment:Condition met! Do stuff here. ◆Exit Event Processing ◆ :End ◆ :End ◆ :End ◆Comment:Condition not met.
Otherwise you could try something like this in Conditional Branch -> Script:
JavaScript:
const v = $gameVariables.value(1); [2,3,4,5].every(id => v >= $gameVariables.value(id))
I.e. "true iff the values of game variables 2, 3, 4, and 5 are all >= the value of game variable 1". Technical details here:
[Edit: replaced var with const just because.]
Thanks!
Well almost there!
I want to put not greater or equal, but just greater (>)
I put this way, but did not work
What is wrong?
I just remove = symbol

var v = $gameVariables.value(1); [2,3,4,5].every(id => v = $gameVariables.value(9))
Thanks!
Well almost there!
I want to put not greater or equal, but just greater (>)
I put this way, but did not work
What is wrong?
I just remove = symbol

var v = $gameVariables.value(1); [2,3,4,5].every(id => v = $gameVariables.value(9))
You didn't remove the =, you removed the >. Do that the other way round and it'll work. 😛
You didn't remove the =, you removed the >. Do that the other way round and it'll work. 😛
Ah yes, sorry!
Worked!
Thanks also caethyril
JavaScript:
const v = $gameVariables.value(1); [2,3,4,5].every(id => v >= $gameVariables.value(id))
I.e. "true iff the values of game variables 2, 3, 4, and 5 are all >= the value of game variable 1".
Isn't that backwards? I think you typed it correctly but described it backwards 😉

You didn't remove the =, you removed the >. Do that the other way round and it'll work. 😛
Almost...for some reason, he also changed $gameVariables.value(id) to $gameVariables.value(9)

So, @Decinbr get rid of that 9 and change it to >
Isn't that backwards? I think you typed it correctly but described it backwards 😉


Almost...for some reason, he also changed $gameVariables.value(id) to $gameVariables.value(9)

So, @Decinbr get rid of that 9 and change it to >
Well, i put this way and seems to work:
const v = $gameVariables.value(1388); [1387,1386,1385,1384,1383,1382].every(id => v < $gameVariables.value(1381))
😅 Whoops, yes, sorry for the confusion! I edited my previous post.
Well, i put this way and seems to work:
const v = $gameVariables.value(1388); [1387,1386,1385,1384,1383,1382].every(id => v < $gameVariables.value(1381))
This checks if the value of variable 1388 is less than the value of variable 1381...and it does that check up to 6 times (once per ID in the list). But you want to check the value of variable id (different value each time), right?

Try this instead:

const v = $gameVariables.value(1388); [1387,1386,1385,1384,1383,1382].every(id => v < $gameVariables.value(id))
I.e.
  • Store the value of game variable ID 1388 in a temporary variable v (will be deleted after the script call ends);
  • Loop through the list of IDs 1387, 1386, 1385, 1384, 1383, 1382:
    • For each ID, test if v is less than the value of the game variable with that ID.
  • Return:
    • true if every ID passed the test;
    • false otherwise.
(I double-checked, pretty sure the code matches the description this time. 😊)

In case it helps to clarify what's going on: the id => stuff part is called an "arrow function". every calls that function once per value in the array, with id replaced by the value each time.
😅 Whoops, yes, sorry for the confusion! I edited my previous post.

This checks if the value of variable 1388 is less than the value of variable 1381...and it does that check up to 6 times (once per ID in the list). But you want to check the value of variable id (different value each time), right?

Try this instead:

const v = $gameVariables.value(1388); [1387,1386,1385,1384,1383,1382].every(id => v < $gameVariables.value(id))

I.e.
  • Store the value of game variable ID 1388 in a temporary variable v (will be deleted after the script call ends);
  • Loop through the list of IDs 1387, 1386, 1385, 1384, 1383, 1382:
    • For each ID, test if v is less than the value of the game variable with that ID.
  • Return:
    • true if every ID passed the test;
    • false otherwise.
(I double-checked, pretty sure the code matches the description this time. 😊)

In case it helps to clarify what's going on: the id => stuff part is called an "arrow function". every calls that function once per value in the array, with id replaced by the value each time.
Thanks, worked!
I think javascript `max` function should do the trick:

JavaScript:
if($gameVariables.value(1)> Math.max($gameVariables.value(2),$gameVariables.value(3),$gameVariables.value(4))){
  // do magical stuff
}
JavaScript:
const v = $gameVariables.value(1); [2,3,4,5].every(id => v >= $gameVariables.value(id))
I.e. "true iff the values of game variables 2, 3, 4, and 5 are all < the value of game variable 1". Technical details here:

@caethyril Thanks for your exemple. You save my day.

Original thread: https://forums.rpgmakerweb.com/threads/help-how-to-check-variable-1-is-greater-than-multiple-variables-2-3-4-5.147161/