How to find Variable with Highest Value?

Pretty much, let's say I have a bunch of variables, and I wish to find out which one is the highest, how would I do so?

I created this:

var maxValue = Math.max($gameVariables[1], $gameVariables[2], $gameVariables[3], $gameVariables[4], $gameVariables[5]); if($gameVariables[1] == maxValue)$gameVariables[6] = 1;if($gameVariables[2] == maxValue)$gameVariables[6] = 2;if($gameVariables[3] == maxValue)$gameVariables[6] = 3;if($gameVariables[4] == maxValue)$gameVariables[6] = 4;if($gameVariables[5] == maxValue)$gameVariables[6] = 5;but it has failed to work. 

Can someone explain what I need to do?
Hmm... when I look at the Game_Variables class, you have to use $gameVariables.value(1) to get the value of the first variable.
end_variable_id = 0help_value = 0for id in (1..50) #<--Variable_Idsif $game_variables[id] >= help_valueend_variable_id = idhelp_value = $game_variables[id]endendNow somehow using the id safed in end_variable_id somehow for your stuff, or exchange end_variable_id with a $game_variables[?]Iam not a Scripter but maybe this somehow helps.
Hmm... when I look at the Game_Variables class, you have to use $gameVariables.value(1) to get the value of the first variable.
Oh my god!

That makes so much more sense.

Everything works now.

I also switched my code to this:

var maxValue = 0;for(i = 0; i < 5; i++){  if($gameVariables.value(i) > maxValue)  {    maxValue = $gameValue.value(i); $gameVariables.setValue(6, i);  }}so for anyone reading this later, that's how you do it.
Nice....but thats to high for me at the moment as starter...
Oh my god!

That makes so much more sense.

Everything works now.

I also switched my code to this:

var maxValue = 0;for(i = 0; i < 5; i++){  if($gameVariables.value(i) > maxValue)  {    maxValue = $gameValue.value(i); $gameVariables.setValue(6, i);  }}so for anyone reading this later, that's how you do it.
Hmm... are you sure that it works as intended?

You start at $gameVariables.value(0) and end at $gameVariables.value(4).

As far as I know, MV don't save anything from the database (items, classes, variables) at array index 0.

And in your code before, you took the indexes 1 'tll 5.

Nice....but thats to high for me at the moment as starter...
It is, to some extent, the same method you described.

But it is simpler in regards to only use one variable, not two 😀
Hmm... are you sure that it works as intended?

You start at $gameVariables.value(0) and end at $gameVariables.value(4).

As far as I know, MV don't save anything from the database (items, classes, variables) at array index 0.

And in your code before, you took the indexes 1 'tll 5.
Oh wow, that's embarrassing.

Yeah, you're right, I made a little typo.

It's actually:

var maxValue = 0;for(i = 1; i <= 5; i++){  if($gameVariables.value(i) > maxValue)  {    maxValue = $gameValue.value(i); $gameVariables.setValue(6, i);  }}Thanks for pointing that out.

When I wrote it here, I did it by memory and I wrote the for-loop the way I usually do instead of the altered method needed for this.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-find-variable-with-highest-value.49824/