SA-MP Forums Archive
Checking if a string doesn't match, doesn't work? - 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: Checking if a string doesn't match, doesn't work? (/showthread.php?tid=574634)



Checking if a string doesn't match, doesn't work? - Dokins - 19.05.2015

pawn Code:
if(strcmp(plate, VehPlate[x], false))return SendClientMessage(playerid, COLOUR_GREY, "That license plate does not exist.");
This returns each time.

Is that correct?


Re: Checking if a string doesn't match, doesn't work? - MP2 - 19.05.2015

If you're checking if they DO match, you need to check if the return value is false.

i.e.
pawn Code:
if(!strcmp(...))



Re: Checking if a string doesn't match, doesn't work? - Dokins - 19.05.2015

I see thank you!


Re: Checking if a string doesn't match, doesn't work? - Threshold - 19.05.2015

But he's checking if they 'don't' match, which is the exact opposite. The code you have now is correct, but it will be case sensitive.

So lets say a valid license plate was "ABC123". If you put in 'abc123', it will return true and it will say the license plate does not exist. However if you put 'ABC123', it will return false and the plates will match. To remove this, just change the case sensitivity or 'ignorecase' to true.

If this code doesn't work, then your VehPlate[x] or possibly the loop that you're using it in, is wrong.
pawn Code:
if(strcmp(plate, VehPlate[x], true)) return SendClientMessage(playerid, COLOUR_GREY, "That license plate does not exist.");
Take note, strcmp also returns false if either of the strings is empty.


Re: Checking if a string doesn't match, doesn't work? - Dokins - 19.05.2015

Thank you! I was looking incorrectly as I didn't put a condition and it used the first result in the loop each time, resolved!