Picking the highest variable from 5 + checking if the highest are equal

There were a few legacy threads about this sort of thing, but I searched through them and was a little confused / not sure if the information was updated for MZ, so I thought I'd make a post detailing my specific question.


I'm looking to make a sort of alignment system for my current project- with the player's choices each adding to a separate variable for the 5 different types of alignment. I want to have an NPC who reacts differently based on the player's highest alignment value, and also reacts differently if the two (or more) highest alignment values are equal to one another. I started to make a complex event chain for this, but got stuck when I realized that checking if the two highest values were equal would be even more complicated than the event already was.

From what I've seen, the best way to do this would *probably* be a script call, unless there's a plugin or eventing trick I've overlooked- I'm just not exactly sure how one would go about doing that script call.
I am surprised none of the Javascript wizards here answered this?!

var alignments = [ 0, 6, 10, 10];
alignments.sort((a,b)=> b-a);
if (alignments[0] == alignments[1]){
//Wow, you have two alignments that are equally high
}

replace the 0, 6, 10, 10 values in the alignment array with variable references
First of all, thank you so much for responding! I tried my hand at adapting that script call and ended up with this:


JavaScript:
var alignments = [ $gameVariables(15), $gameVariables(16), $gameVariables(17), $gameVariables(18), $gameVariables(19) ];
alignments.sort((a,b)=> b-a);
if (alignments[0] == alignments[1]){
$gameMessage.setBackground(0);
$gameMessage.setPositionType(2);
$gameMessage.add("The fox looks at you with a gaze full of confusion, as if it doesn't quite know what to make of you.");
}
if (alignments[0] == $gameVariables(15)){
$gameMessage.setBackground(0);
$gameMessage.setPositionType(2);
$gameMessage.add("The fox looks at you with a mistrustful gaze, as if it finds you to be a threat, or at the very least unpredictable.");
}

When I tested it ingame with different variable values, the event did absolutely nothing when the script call came in- interacting with it just made the event briefly turn to the player and then turn back. I also tried this with a version that just used the numbers of the variables instead $gameVariables, but no dice on that either. I'd really appreciate it if someone could point out my (probably) obvious mistake.
>.<
It should be: $gameVariables.value(X)

EDIT: Also, like that, I think nothing happens unless your variable 15 is the highest (or there's equal values).

EDIT EDIT: Also, if you write it like that, and your variable 15 is the highest, but one of the others is equal, it shows both texts.
It should be: $gameVariables.value(X)

EDIT: Also, like that, I think nothing happens unless your variable 15 is the highest (or there's equal values).

EDIT EDIT: Also, if you write it like that, and your variable 15 is the highest, but one of the others is equal, it shows both texts.

Thank you! I managed to get it working with your help 😀

Original thread: https://forums.rpgmakerweb.com/threads/picking-the-highest-variable-from-5-checking-if-the-highest-are-equal.159743/