strcmp bug/issue
#1

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

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

http://pastebin.com/Aqk1haFW
Reply
#4

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

Not really. He was checking if the house's owner WASN'T "for sale" and putting the green icon up. The check was reversed.
Reply
#6

Well he said he had tried the other ways (changing the result) so I assumed they did not work.
Reply
#7

Quote:
Originally Posted by bigcomfycouch
View Post
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)