How can I compare multiple variables at once?

arekpowalan

Veteran
Veteran
Joined
Feb 20, 2013
Messages
143
Reaction score
48
First Language
Thai
Primarily Uses
RMMV
First, let me elaborate. I am doing an event where when a specific dialogue appears based on the competition of multiple variables for the highest or a specific ranking. This is because my game is operated by a dating sim mechanic with an "affection point". For example, when cut scene plays to the certain point, one of the characters will say this to the hero.
I love you because...
For a sample context, there are five characters: Anny, Betty, Calsa, Daria, and Emy. Each character's affection point is dictated by the a variable "actor(x) Love Point". These five variables will be compared a moment before this message box appears. Whoever has the most (or second, or third, etc.) "actor(x) Love Point" will get to say the quote (ex. A = 10 > B, C, D, E). This message will be different based on the character who says it such as:
Anny: I love you because you're brave.
Betty: I love you because you're funny.
Calsa: I love you because you provides for me.
Daria: I love you because you are amusing me.
Emy: I love you because you reminds me of my brother.
My main issue is that I only know how to compare two variables at once. As such, trying to compare five at once can become very confusing. There is also a situation where I would like a character with the second/third most affection or even the least affection to get to say something.

Is comparison like this possible with the default RMMV editor? Or do I need a plugin for it? Thank you in advance.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,366
Reaction score
7,676
First Language
German
Primarily Uses
RMMV
No programmer ever has been able to compare more than one variable with one other. It always requires a sequence of two pair comparisons to compare more than one variable.
It is only that in some programming languages, this sequence is preprogrammed to use - but there is no technical way to have a Computer compare more than two variables in a single step.

Depending on what you want you'll need a sorting algorithm either implemented by a series of control variable and conditional branches or by script functions.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,091
Reaction score
1,508
First Language
EN
Primarily Uses
RMMZ
Like Andar says, you could do this with eventing and an awful lot of branches, but a sorted array is probably a better option. Perhaps a script call something like this?
Code:
var points = [], ids = [1,2,3,4,5];
ids.forEach(function(e) { points.push({ id: e, value: $gameVariables.value(e) }); });
points.sort(function(a, b) { return b.value - a.value; });
$gameVariables.setValue(6, points[0].id);
In English:
  • Let points be an empty array and ids be an array of the "lovePoint" variable IDs (in this case #1, #2, #3, #4, #5);
  • For each entry in ids, add a new entry into points containing the variable ID and the value of that variable;
  • Sort points descending by value, i.e. put the highest value at the start of the list;
  • Set variable #6 to the ID of the first entry in points, i.e. the ID of the highest-value variable.
You'll probably need to change the numbers for your situation, but I did a quick test and it worked for me! :kaothx:
 

arekpowalan

Veteran
Veteran
Joined
Feb 20, 2013
Messages
143
Reaction score
48
First Language
Thai
Primarily Uses
RMMV
I've tried caethyril's solution and it works. I'm quite new to coding, so I may need to look more into it. Thank you very much.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,081
Members
137,582
Latest member
Spartacraft
Top