strcmp bug/issue - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: strcmp bug/issue (
/showthread.php?tid=181911)
strcmp bug/issue -
Toni - 07.10.2010
Well we all know strcmp has that bug of returning false if it returns a valid value.
I can't seem to find a way to change the pickup model depending on the name.
Here is my code:
pawn Code:
function AddHouses(HouseID)
{
DestroyHouses(HouseID)
HouseInfo[HouseID][LabelID] = Create3DTextLabel(str, CYAN, HouseInfo[HouseID][EntX], HouseInfo[HouseID][EntY], HouseInfo[HouseID][EntY], 30.0, -1, 1);
if(strcmp(HouseInfo[HouseID][Owner], "For Sale", true) == 1)
{
HouseInfo[HouseID][PickupID] = CreatePickup(1273, 23, HouseInfo[HouseID][EntX], HouseInfo[HouseID][EntY], HouseInfo[HouseID][EntZ], -1); //Green
}
else if(strcmp(HouseInfo[HouseID][Owner], "For Sale", true) == 0)
{
HouseInfo[HouseID][PickupID] = CreatePickup(1272, 23, HouseInfo[HouseID][EntX], HouseInfo[HouseID][EntY], HouseInfo[HouseID][EntZ], -1); //Blue
}
return 1;
}
I've tried tons of things, switching the values ( == 1/ == 0). But none of it just works.
The problem is that no matter what the House owner's name is, it will be green; meaning the house can be bought.
If I switch the values the other way where == 1 is in the second else if, the same thing happens. But the model is blue this time. No matter the name.
If this doesn't work, I'll just use a var to see if its owned or not.
Re: strcmp bug/issue -
Lenny the Cup - 07.10.2010
That's not a bug, the function is designed that way.
Try putting a max-length on the strcmp, you know the string won't be longer than 8 characters anyway.
Re: strcmp bug/issue -
bigcomfycouch - 07.10.2010
http://pastebin.com/Aqk1haFW
Re: strcmp bug/issue -
Grim_ - 07.10.2010
A max length isn't needed, hence an optional paramater.
The only problem would be the Owner's name not correctly being extracted into the array - Show where you do this.
@bigconfycouch: Your code does the same thing, just in a different manner.
Re: strcmp bug/issue -
bigcomfycouch - 07.10.2010
Not really. He was checking if the house's owner WASN'T "for sale" and putting the green icon up. The check was reversed.
Re: strcmp bug/issue -
Grim_ - 07.10.2010
Well he said he had tried the other ways (changing the result) so I assumed they did not work.
Re: strcmp bug/issue -
Toni - 08.10.2010
Quote:
Originally Posted by bigcomfycouch
Not really. He was checking if the house's owner WASN'T "for sale" and putting the green icon up. The check was reversed.
|
@ Grim_ you're correct.
I already tried that, and it ended up with the same results.
People can forget this, I'll just add a bool with a IsOwned.