Simple if check - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Simple if check (
/showthread.php?tid=655888)
Simple if check -
GospodinX - 02.07.2018
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..
Re: Simple if check -
Calisthenics - 02.07.2018
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".
Re: Simple if check -
GospodinX - 02.07.2018
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!
Re: Simple if check -
Calisthenics - 02.07.2018
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)