SA-MP Forums Archive
two parents in a conditional - 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: two parents in a conditional (/showthread.php?tid=659233)



two parentheses in a conditional - Electrifying - 28.09.2018

What does two parentheses mean on a conditional? like
Код:
if(! (3 <= strlen( inputtext ) <= 20))
Код:
if( (pInfo[i][AdminLevel] > pInfo[playerid][AdminLevel] ) && (pInfo[i][AdminLevel] >= 2) && (i != playerid)



Re: two parents in a conditional - NaS - 28.09.2018

Quote:
Originally Posted by Electrifying
Посмотреть сообщение
What does two parentheses mean on a conditional? like
Код:
if(! (3 <= strlen( inputtext ) <= 20))
Код:
if( (pInfo[i][AdminLevel] > pInfo[playerid][AdminLevel] ) && (pInfo[i][AdminLevel] >= 2) && (i != playerid)
There is a specific order in which they are processed.

Very similar to this:

Код:
5 + 6 * 7 = 47
is not the same as

Код:
(5 + 6) * 7 = 77
The same can be said about conditions. Some expressions are meant to be concatenated.

Код:
if(3 <= strlen( inputtext ) <= 20)
will check if strlen(inputtext) is greater than or equal to 3 and smaller than or equal to 20.

With the additional brackets and the exclamation mark, this will negate the outcome of this check. So this:

Код:
if(! (3 <= strlen( inputtext ) <= 20))
will check if strlen(inputtext) is NOT in the specified range.

Same for expressions where AND and OR are used at the same time, there is a specific order and when it's not respected the outcome will be totally different.

So this:

Код:
if(var1 == 3 && var2 == 4 || var == 4 && var2 == 3)
is very different from this:

Код:
if((var1 == 3 && var2 == 4) || (var == 4 && var2 == 3))
The first one will not accept any values, as the check will fail at the second AND.

The second code will accept 3 & 4 OR 4 & 3 respectively.


Re: two parents in a conditional - Electrifying - 28.09.2018

Quote:
Originally Posted by NaS
Посмотреть сообщение
There is a specific order in which they are processed.

Very similar to this:

Код:
5 + 6 * 7 = 47
is not the same as

Код:
(5 + 6) * 7 = 77
The same can be said about conditions. Some expressions are meant to be concatenated.

Код:
if(3 <= strlen( inputtext ) <= 20)
will check if strlen(inputtext) is greater than or equal to 3 and smaller than or equal to 20.

With the additional brackets and the exclamation mark, this will negate the outcome of this check. So this:

Код:
if(! (3 <= strlen( inputtext ) <= 20))
will check if strlen(inputtext) is NOT in the specified range.

Same for expressions where AND and OR are used at the same time, there is a specific order and when it's not respected the outcome will be totally different.

So this:

Код:
if(var1 == 3 && var2 == 4 || var == 4 && var2 == 3)
is very different from this:

Код:
if((var1 == 3 && var2 == 4) || (var == 4 && var2 == 3))
The first one will not accept any values, as the check will fail at the second AND.

The second code will accept 3 & 4 OR 4 & 3 respectively.
Thanks!!


Re: two parents in a conditional - v1k1nG - 28.09.2018

Well thread title look cool anyways


Re: two parents in a conditional - TheToretto - 28.09.2018

lmao I thought your parents were in conditional sentence


Re: two parents in a conditional - Electrifying - 28.09.2018

Quote:
Originally Posted by TheToretto
Посмотреть сообщение
lmao I thought your parents were in conditional sentence
hahaha I noticed, sorry I don't speak english