SA-MP Forums Archive
"||" statement not working within if 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: "||" statement not working within if statement. (/showthread.php?tid=314782)



"||" statement not working within if statement. - Dokins - 31.01.2012

pawn Код:
if(!IsPlayerInRangeOfPoint(playerid, 20.0, -240.2907,1209.9883,19.7422)|| !IsPlayerInRangeOfPoint(playerid, 50.0,-1327.7439,2675.7014,50.0625)|| !IsPlayerInRangeOfPoint(playerid, 10.0, 609.0861,1698.3657,6.9922)) return SendClientMessage(playerid, COLOUR_GREY, "You must be at a Gas Station to refuel.");
It always returns: You must be at a Gas Station to refuel, although I'm in range of the points.


Re: "||" statement not working within if statement. - milanosie - 31.01.2012

Dont use the !

Make it in a way it only continues if it is TRUE instead of FALSE

thats how I always work


Re: "||" statement not working within if statement. - Dokins - 31.01.2012

So how would I re-write it?


Re: "||" statement not working within if statement. - CaHbKo - 31.01.2012

pawn Код:
if(IsPlayerInRangeOfPoint(playerid, 20.0, -240.2907,1209.9883,19.7422)|| IsPlayerInRangeOfPoint(playerid, 50.0,-1327.7439,2675.7014,50.0625)|| IsPlayerInRangeOfPoint(playerid, 10.0, 609.0861,1698.3657,6.9922))
{
    //do shit
}
else return SendClientMessage(playerid, COLOUR_GREY, "You must be at a Gas Station to refuel.");



Re: "||" statement not working within if statement. - Vince - 31.01.2012

The double pipes mean OR, not AND. In your case you need AND (&&). I read code in my mind like this:

if not IsPlayerInRangeOfPoint OR not IsPlayerInRangeOfPoint OR not IsPlayerInRangeofPoint then do : ...

As you can see, it doesn't make sense. This however, makes a lot more sense:

if not IsPlayerInRangeOfPoint AND not IsPlayerInRangeOfPoint AND not IsPlayerInRangeOfPoint then do : ...


Re: "||" statement not working within if statement. - [ABK]Antonio - 31.01.2012

pawn Код:
if(IsPlayerInRangeOfPoint(playerid, 20.0, -240.2907,1209.9883,19.7422) || IsPlayerInRangeOfPoint(playerid, 50.0,-1327.7439,2675.7014,50.0625)|| IsPlayerInRangeOfPoint(playerid, 10.0, 609.0861,1698.3657,6.9922))
{
    //our stuff
}
else return SendClientMessage(playerid, COLOUR_GREY, "You must be at a Gas Station to refuel.");
Makes it so if they're at any of them we'll do somethin

EDIT: lol...seems I was beat to the punch


Re: "||" statement not working within if statement. - Dokins - 31.01.2012

Thanks Vince, that's made it a lot clearer for me to understand!