"||" statement not working within if statement.
#1

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.
Reply
#2

Dont use the !

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

thats how I always work
Reply
#3

So how would I re-write it?
Reply
#4

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.");
Reply
#5

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 : ...
Reply
#6

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
Reply
#7

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


Forum Jump:


Users browsing this thread: 1 Guest(s)