Simple if check
#1

I have three variable:

Код:
Variable1
Variable2
Variable3
Now,i need to make check that it need to be true for:
Код:
Variable1 > 0
Variable2 > 0 && Variable2 < 6
Variable3 > 0
So,if i have Variable2 = 8,it need to be false! (because : "Variable2 > 0 && Variable2 < 6" )

I'm do this:

Код:
if(Variable1[playerid] > 0 || Variable2[playerid] > 0 || Variable3[playerid] > 0 && Variable2[playerid] < 6)
But it don't work..
Reply
#2

Use parentheses when needed:
pawn Код:
if (Variable1[playerid] > 0 || (Variable2[playerid] > 0 && Variable2[playerid] < 6) || Variable3[playerid] > 0)
You did not mention, do all these three variables need to be "true"? Because you used || (OR) which checks if any of the three is "true".
Reply
#3

Quote:

You did not mention, do all these 3 variables need to be "true"? Because you used || (OR) which it checks if any of the 3 is "true".

Yeah..If any of 3 variable are > 0 it need to be true,except if variable2 > 6 it need to be false.

Thank you!
Reply
#4

What you can do is let it check the Variable2 first:
pawn Код:
if ((Variable2[playerid] > 0 && Variable2[playerid] < 6) || Variable1[playerid] > 0 || Variable3[playerid] > 0)
So if Variable2 >= 6, it is false directly. If it isn't, it checks if the last two are true.

Another way (preferable) would be to check all three of them for being > 0 and check Variable2 < 6 last:
pawn Код:
if ((Variable1[playerid] > 0 || Variable2[playerid] > 0 || Variable3[playerid] > 0) && Variable2[playerid] < 6)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)