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,679
Reaction score
8,492
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

Stream will be live with some Dark Souls 3, followed by a session of the Interactive Text Adventure! Feel free to drop by!
I THINK I have a slightly better grasp on drawing my maps now... sorta. I still need to figure out how to draw a city of sorts. I've only got the abstract going so far.
One day, I'll not have this lingering cough and we'll have another make a game stream.
A music I create while practicing E Major scale. :D

Forum statistics

Threads
115,191
Messages
1,087,988
Members
149,771
Latest member
magenz
Top