Picking the highest variable out of many variables

Status
Not open for further replies.

TziaYu

Villager
Member
Joined
Jan 7, 2019
Messages
10
Reaction score
5
First Language
English
Primarily Uses
RMMV
There are 7 variables for 7 events. I don't know how to make the specific event occur if the variables are the highest compared to the other variables.
 

Pots Talos

Veteran
Veteran
Joined
Jun 28, 2012
Messages
172
Reaction score
169
First Language
English
Primarily Uses
RMMV
Are you looking for something like this?


Code:
var tempArray = [$gameVariables.value(101), $gameVariables.value(102), $gameVariables.value(103), $gameVariables.value(104)];

Array.max = function( array ){

return Math.max.apply( Math, array );

};
 

TziaYu

Villager
Member
Joined
Jan 7, 2019
Messages
10
Reaction score
5
First Language
English
Primarily Uses
RMMV
Are you looking for something like this?


Code:
var tempArray = [$gameVariables.value(101), $gameVariables.value(102), $gameVariables.value(103), $gameVariables.value(104)];

Array.max = function( array ){

return Math.max.apply( Math, array );

};
idk what this is to be honest. So basically I have 7 event tied to 7 variable and whichever variable is highest thats the event to occur.
 

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
16,123
Reaction score
8,932
First Language
English
Primarily Uses
RMMV
Can you explain a little more? What sets the variable? Are the variables different items the player collects? I feel like there are probably ways it can be evented but without knowing exactly what you are trying to do, it is hard to know what to advise.
 

TziaYu

Villager
Member
Joined
Jan 7, 2019
Messages
10
Reaction score
5
First Language
English
Primarily Uses
RMMV
its like a quiz where u answer different questions and each answer will add more to each variable. Each variable is like for each stat: atk def, etc.
So I want the biggest variable for e.g they answered correctly for the question their attack will increase. But if they answered more questions correctly for defense oriented questions they get more defense.
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,502
Reaction score
412
First Language
German
Primarily Uses
RMMV
Pseudocode for Variable Comparsion: Eventcommand "Script":
Code:
bex = 0
$gameVarables.setValue(8, 0)
for (var a = 1; a <= 7; a++) {
  if ($gameVariables.value(a) > bex) {
    bex = $gameVariables.value(a)
    $gameVarables.setValue(8, a)
  } }
We are checking the variables 1 to 7 and game variable 8 will contain the id number of the variable with the highest value.
So you can use Variable 8 for further Eventing or for your Eventpage conditions.
If 2 Variables have the same value, than the one with lower id will be choosen as the higher one.

Edit:
I posted this Loop Snippet, because this saves you from having to make a big amount of conditional branches and all the math with events. Events sadly dont have this variable pointer function. I read in rm2k or rm2k3 that they had it in the editor as standard.
 
Last edited:

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
6,115
Reaction score
5,818
First Language
English
Primarily Uses
RMVXA
The Eventing way to do it would be to set an 8th variable to 0, then compare the 8th variable to each of the other 7 variables, and if the other variable is higher than the 8th variable, then set the 8th variable equal to its value. After doing it all 7 times, the 8th variable will be equal to the highest value from the other 7.

Then, if you need to find which variable was the highest of the 7, create a 9th variable, and compare this new 8th variable to each of the original 7 variables again - this time, if the values are equal, use the 9th variable to store the ID of the variable that it matched. So for example, if Variable #3 matches Variable #8, then set Variable #9 to the value "3".
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,502
Reaction score
412
First Language
German
Primarily Uses
RMMV
He can do that the first Time he goes through them. No need for a second loop. But yes 9 Variables he need.
In the script snippet above i just used 8 game variables and a 9th temporary one that is deleted the moment the snippet finishes.
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
6,115
Reaction score
5,818
First Language
English
Primarily Uses
RMVXA
He can do that the first Time he goes through them. No need for a second loop. But yes 9 Variables he need.
In the script snippet above i just used 8 game variables and a 9th temporary one that is deleted the moment the snippet finishes.

Correct, and in fact that's how I generally do it when I don't use code, but I find it's much easier to conceptualize as two separate runs through the variables.
 
  • Like
Reactions: Bex

Jade010

Villager
Member
Joined
May 26, 2021
Messages
6
Reaction score
24
First Language
English
Primarily Uses
RMMZ
I needed some help with this too. But im using 12 variables. a few points will be distributed into each variable once each question is answered and i need it to use the variable with the highest variable. once thats done, i need it to act on that variable. Any tips on how to do this?
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
43,435
Reaction score
15,227
First Language
English
Primarily Uses
RMMV

@Jade010, please refrain from necro-posting in a thread. Necro-posting is posting in a thread that has not had posting activity in over 30 days. You can review our forum rules here. Thank you.



Your question also does not seem the same as the OP's (but like the OP you need to provide more information). Please start your own thread describing in more detail what you are doing and what result you are after.
 
Status
Not open for further replies.

Latest Threads

Latest Profile Posts

sooo... im gonna go ahead and release all my game ideas on android as Beta. Everyone will be nice right? cause its Beta... right?...

AABS traps and heals (detail is below the YTB desc)
 I may actually have something I can put into the Boss Battle Build Bout by the time it’s due. It won’t be anything spectacular (or even great (and maybe not even good (I have no idea how to do combat (yay for nested parentheses)))), but I might have a submission none the less.
Today's my first login since Jan 2020. Time sure flies. Sorry to everyone's messages i missed.
It's satisfying to master the usage of a hard plugin, then making it do what you want. ( o w o)!!

Forum statistics

Threads
115,407
Messages
1,089,631
Members
150,147
Latest member
Arnard
Top