Strlen not working correctly
#1

I have this in my script:
pawn Код:
new string2[128], namelength = strlen(name);
return format(string2, sizeof(string2), "%s - %d", name, namelength), SendClientMessage(playerid, -1, string2);
Yet the strlen always returns 0. I have tried this:
pawn Код:
new string2[128];
return format(string2, sizeof(string2), "%s - %d", name, strlen(name)), SendClientMessage(playerid, -1, string2);
An example of the printed output would be this:
"Jeff_Wilson - 0", "Jonathan_Walker - 0", "Frank_Morris - 0", all of which are wrong. Can anyone help?
Reply
#2

where do you define 'name'
Reply
#3

In the function header. "name" works correctly though, because when I send the client message containing "name", it is correct.
Reply
#4

Bump
Reply
#5

Bump
Reply
#6

I'm not sure if it would work, because I'm not sure what the function actually returns, but have you tried:
pawn Код:
strlen(GetPlayerNameEx(playerid))
??

Otherwise just try making a new variable and getting the length of that instead.
pawn Код:
new PLAYERSNAME[MAX_PLAYER_NAME];
GetPlayerName(playerid, PLAYERSNAME, MAX_PLAYER_NAME);
/* Whatever goes here */ strlen(PLAYERSNAME) //Etc.
Reply
#7

I can't use GetPlayerName because it's in a function thay doesn't use playerid.
Reply
#8

Is this in a function called by a timer or Call(Local/Remote)Function?
Reply
#9

It is called using SetTimerEx.
Reply
#10

Are you giving it strings? Because that's not properly working. If you use fixes2, however, it should work just fine.

What happens is SetTimerEx stores the strings in a location not inside the PAWN's memory script, so most natives won't accept those memory addresses and simply fail.

You could also work around this by using format to copy the string to another string (strcat and others won't work).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)