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,660
Reaction score
8,483
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 couldn't help myself, so I edited the tiles a bit and made a birdhouse :LZSsmile: I hope I will finish the town today!Screenshot 2021-09-17 134349.png
How do I find the threads I have watched? It's been so long I've forgotten :kaoswt:
So far, this is how the wall tileset its looking in-editor. :kaoswt2:
1631863283853.png
Still thinking on details to add.
Added a plugin to RMMV Plugin Releases with all relevant info but it looks like the topic wasn't approved for whatever reason. Cool.
Working in the IT industry:
- "How long does it take?".
- "It takes 1 month".
- "What if we add more people to the project?".
- "It would take 2 months".

Forum statistics

Threads
115,128
Messages
1,087,440
Members
149,626
Latest member
lucky_Floki
Top