How do I compare a single variable to two other ones?

Alkaline

Veteran
Veteran
Joined
Jun 30, 2020
Messages
40
Reaction score
6
First Language
English
Primarily Uses
RMMV
I've been struggling in being able to get an outcome based on which of the 3 variables is greater at a given moment.

Example:
If Var[A] >= Var and Var[A] >= Var[C]
Show text: "Your A is greater than B and C"

So on and so forth for variables B and C.

When I think about it, it seems simple, but I just can't seem to event it properly :kaoswt:
 

ThreeSixNine

Veteran
Veteran
Joined
Jan 22, 2019
Messages
356
Reaction score
289
First Language
English
Primarily Uses
RMMV
How are you checking the value of the variables?
if you're using a script call in a conditional branch, you can use the code:
JavaScript:
$gameVariables.value(1) >= $gameVariables.value(2) && $gameVariables.value(1) >= $gameVariables.value(3);

This will check if Variable 1 is greater than or equal to Variable 2 and if Variable 1 is greater than or equal to Variable 3, if both of those conditions are true, this code will return true.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
33,670
Reaction score
8,489
First Language
German
Primarily Uses
RMMV
you can't compare three values at once, you need to split this into multiple comparisons of two variables.
compare A and B first, then make a comparison between one of them and the other depending on which one is greater.

and no, combining both comparisons into a single line like @ThreeSixNine said is not a good idea, because that way you would have to make every possible combination into a possible double test.
If you want to determine which of three values is the largest you're better with splitting the logic.
if A>B then
>>> If A>C then A is largest
>>>else C is largest
else if B>C then B is largest
>>>else C is largest
 
Last edited:

ThreeSixNine

Veteran
Veteran
Joined
Jan 22, 2019
Messages
356
Reaction score
289
First Language
English
Primarily Uses
RMMV
you can't compare three values at once, you need to split this into multiple comparisons of two variables.
compare A and B first, then make a comparison between one of them and the other depending on which one is greater.

and no, combining both comparisons into a single line like @ThreeSixNine said is not a good idea, because that way you would have to make every possible combination into a possible double test.
If you want to determine which of three values is the largest you're bettwe with splitting the logic.
if A>B then
>>> If A>C then A is largest
>>>else C is largest
else if B>C then B is largest
>>>else C is largest
I understand what you mean, in the single line, if A < B, it will never check if A > C.
It seems like it would work, but its too rigid and that's probably the nature of why it was alluding the OP.
Thank you for the correction.
 

Latest Threads

Latest Posts

Latest Profile Posts

I might not participate in the Boss Battle contest after all... I have more important things to do, like Wishful Wanda. And of course the Dark Deception spinoff I plan to pitch, Demon Slayer.
Changed my avatar, goodbye Alan Sugar, hello George Carlin (one of my favorite human beings ever)
If you still don't subscribe our Polish channel please consider it :)
1.png
Who wants to see my review of the worst star wars movie? This movie has all the excitement of being on Jury Duty of the most boring case ever about trade negotiations.
A lot to learn to make a game. Can I handle it?

Forum statistics

Threads
115,171
Messages
1,087,798
Members
149,720
Latest member
Kirbyslasher
Top