BUD::How to get a name to a string?
#1

strcmp fails? it still gets passed somehow, why is that?
pawn Код:
for(new i = 0; i < MAX_PLAYERS; ++i)
            {
                if(strcmp(DynamicHouses[houseid][hRenter1], PlayerName(i), true)) // its passing even when the names aren't the same, why?
                {
                    print("PASS");
                }
            }
Reply
#2

try this:

pawn Код:
new name2[MAX_PLAYER_NAME];
            format(name2, MAX_PLAYER_NAME, "%s", DynamicHouses[houseid][hRenter1]);
            for(new i = 0; i < MAX_PLAYERS; ++i)
            {
                if(strcmp(name2, PlayerName(i), true))
                {
                    printf("naame2: %s", name2);
                    printf("PlayerName(i): %s", PlayerName(i));
                    printf("i: %d", i);
                }
            }
Reply
#3

Quote:
Originally Posted by MeDaKewlDude
Посмотреть сообщение
try this:

pawn Код:
new name2[MAX_PLAYER_NAME];
            format(name2, MAX_PLAYER_NAME, "%s", DynamicHouses[houseid][hRenter1]);
            for(new i = 0; i < MAX_PLAYERS; ++i)
            {
                if(strcmp(name2, PlayerName(i), true))
                {
                    printf("naame2: %s", name2);
                    printf("PlayerName(i): %s", PlayerName(i));
                    printf("i: %d", i);
                }
            }
Yes, i noticed my mistake there... *facepalm*

But the problem now is, that strcmp fails or something, my code looks like this now:
pawn Код:
for(new i = 0; i < MAX_PLAYERS; ++i)
            {
                if(strcmp(DynamicHouses[houseid][hRenter1], PlayerName(i), true)) // its passing even when the names aren't the same, why?
                {
                    print("PASS");
                }
            }
Reply
#4

Strcmp returns 0 on success, not 1. i.e. that block will execute whenever the values are not the same and fail whenever the values are the same. To fix, simply add a not operator (!) in front of strcmp.
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
Strcmp returns 0 on success, not 1. i.e. that block will execute whenever the values are not the same and fail whenever the values are the same. To fix, simply add a not operator (!) in front of strcmp.
That still didn't fix it..
Reply
#6

here
pawn Код:
for(new i = 0; i < MAX_PLAYERS; ++i)
            {
                if(!strcmp(DynamicHouses[houseid][hRenter1], PlayerName(i)))
                {
                    print("PASS");
                }
            }
Reply
#7

Quote:
Originally Posted by MeDaKewlDude
Посмотреть сообщение
here
pawn Код:
for(new i = 0; i < MAX_PLAYERS; ++i)
            {
                if(!strcmp(DynamicHouses[houseid][hRenter1], PlayerName(i)))
                {
                    print("PASS");
                }
            }
Thanks!
Reply
#8

NVM!

Seems that i forgot to check IsPlayerConnected... Phew, im glad i solved this problem, after HOURS, lol! *facepalm*
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)