A but statement - 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: A but statement (
/showthread.php?tid=350468)
A but statement -
Faisal_khan - 12.06.2012
Hi SA-MP Community,
I was thinking if there is a but operator like:
pawn Код:
some function..... > 20 but < 40
Re: A but statement -
iggy1 - 12.06.2012
&& should do, if you mean in the english language sense of the word.
But to answer your question, no there is no but operator.
pawn Код:
some function..... > 20 && some function..... < 40
Re: A but statement -
Faisal_khan - 12.06.2012
I want all the values between 20 to 40 included.
&& does'nt work I already tried that.
Re: A but statement -
iggy1 - 12.06.2012
It does work.
pawn Код:
new var = 25;
if( var > 19 && var < 41 )
{
//this will be executed if var is between 20 and 40
}
Re: A but statement -
Revo - 12.06.2012
&& should work.
pawn Код:
if (value >= 20 && value <= 40) { printf("works, %d", value); } else { printf("failed, %d", value); }
Basically saying if the value is greater than or equal to 20 AND less than or equal to 40 execute code. else return false
Re: A but statement -
jessejanssen - 12.06.2012
Quote:
Originally Posted by iggy1
&& should do, if you mean in the english language sense of the word.
But to answer your question, no there is no but operator.
pawn Код:
some function..... > 20 && some function..... < 40
|
Indeed, you should use && ( and ) and || ( or ).
Like:
pawn Код:
new functiona, functionb;
if(!strcmp(cmdtext, "/function", true))
{
new string[110];
functiona = random(10);
functionb = random(10);
// If function a is 8 or higher and function b is 8 or lower.
if(functiona >= 8 && functionb <= 8)
{
format(string, sizeof(string), "> 'Functiona' = '%d' and 'functionb' = '%d'", functiona, functionb);
SendClientMessage(playerid, 0xFFFFFFFF, string);
}
// If function a is lower then 8 or if functionb if higher then 8.
else if(functiona < 8 || functionb > 8)
{
format(string, sizeof(string), "> 'Functiona' = '%d' and 'functionb' = '%d'", functiona, functionb);
SendClientMessage(playerid, 0xFFFFFFFF, string);
}
}
It's a useless code, but it should explain how to use it.
Best regards,
Jesse
Re: A but statement -
iggy1 - 12.06.2012
pawn Код:
switch(var)
{
case 20 .. 40:
{
//this will also be executed if var is between 20 and 40
}
}
Re: A but statement -
Faisal_khan - 12.06.2012
LOL I did not read further I was doing it last night like this:
pawn Код:
some function.... > 20 && < 40
I will try your one.
Re: A but statement -
Faisal_khan - 12.06.2012
Yeah it works thanks all +rep to all.
Re: A but statement -
Jochemd - 12.06.2012
Don't forget to use
<= !!! Currently it means: if some function is 21 or higher and 39 or lower!