Script in conditional branch failing

Hello, I have an array where there are 4 choices presented 4 different times. I want to do something based on the most frequently-selected choice.

Using a conditional branch I'm able to use variations of the following, which returns the correct result when one choice has more selections than the others.

$gameVariables.value(21) > $gameVariables.value(22) && $gameVariables.value(21) > $gameVariables.value(23) && $gameVariables.value(21) > $gameVariables.value(24)

Else


$gameVariables.value(22) > $gameVariables.value(21) && $gameVariables.value(22) > $gameVariables.value(23) && $gameVariables.value(22) > $gameVariables.value(24)

And so on.

The problem is when there are two choices that were selected the same amount of times. I am using the following, which I hope would check if variable 21 and 22 are equal and also greater than the other variables. But the game doesn't return a result:

$gameVariables.value(21) == $gameVariables.value(22) && $gameVariables.value(21) > $gameVariables.value(23) && $gameVariables.value(21) > $gameVariables.value(24)

What am I doing wrong? Thanks in advance!
you are missing priorities - some operations have higher priority than others, and if that is the case you'll need to use ( ) to tell the engine where you want the calculations to take place.

try
($gameVariables.value(21) === $gameVariables.value(22)) && ( and so on.

EDIT: third = added because that is needed for some comparisons in javscript, you forgot that as well
This is the first I've heard of priorities and using === for comparisons. I tried the below and it's not working - any advice? Thank you.

($gameVariables.value(21) === $gameVariables.value(22)) && ($gameVariables.value(21) > $gameVariables.value(23)) && ($gameVariables.value(21) > $gameVariables.value(24))
then give a look at the entire sequence - what is not working and how do you know it's not working?

because if that is not working, then you made a mistake with the general logic and not that line alone.
Oh no, you saying that made me decide to test in different circumstances. Apparently it works unless I'm relying on a plugin I'm using. I'll troubleshoot from here, I appreciate it.
you can also divine them first like:
scriptcall:

let Gv1 = $gameVariables.value(21);
let Gv2 = $gameVariables.value(22);
let Gv3 = $gameVariables.value(23);
let Gv4 = $gameVariables.value(24);
if (Gv1 >= Gv2 && Gv3 &&Gv4)
do whatever it need to be done}
else if (Gv2 >= Gv1 && Gv3 && G4) etc
another way to simplify a conditional branch, use conditionalBranch+
to simplify variables check as well, and specially in an array.

rather to call them fully out. to use a simple way.
you can also divine them first like:
scriptcall:

let Gv1 = $gameVariables.value(21);
let Gv2 = $gameVariables.value(22);
let Gv3 = $gameVariables.value(23);
let Gv4 = $gameVariables.value(24);
if (Gv1 >= Gv2 && Gv3 &&Gv4)
do whatever it need to be done}
else if (Gv2 >= Gv1 && Gv3 && G4) etc
another way to simplify a conditional branch, use conditionalBranch+
to simplify variables check as well, and specially in an array.

rather to call them fully out. to use a simple way.

Thank you! But, I have never defined variables like this before - is it a matter of copying and pasting exactly what you've typed above? Is "let abc = $gameVariables.value(1);" the actual syntax? And, where/how would I put this in RMMV? I'm a 7/10 in making events and variables in RMMV but only know bits of pieces of code.

I'll look into conditionalBranch+ as well, thanks for the recommendation.
So...I'm going to go against the flow here.

- You do not need parentheses. Greater than, less than, and equality all have higher operator precedence than logical AND, so your original grouping works fine.

- There's also no reason to use strict equality here, because you know you're comparing numerical values. Using === only serves a purpose when there's a possibility of comparing variables of different data types. It wouldn't make your code not work, but it also won't make it work any better.

- You do not need to create extra variables unless it pleases you and helps you to read.

The problem is when there are two choices that were selected the same amount of times. I am using the following, which I hope would check if variable 21 and 22 are equal and also greater than the other variables. But the game doesn't return a result:

$gameVariables.value(21) == $gameVariables.value(22) && $gameVariables.value(21) > $gameVariables.value(23) && $gameVariables.value(21) > $gameVariables.value(24)

What am I doing wrong? Thanks in advance!
I would cut down on how many different conditions you have and just use >=, then it will evaluate as true whether 21 has been picked more than the other OR the same number of times.

You can also consolidate your code greatly with a call to a built-in JavaScript function. Math.max() returns the highest of several provided values. So:
Code:
$gameVariables.value(21)>=Math.max($gameVariables.value(22), $gameVariables.value(23), $gameVariables.value(24))

Original thread: https://forums.rpgmakerweb.com/threads/script-in-conditional-branch-failing.142899/