Differences
#1

I have been using,
pawn Код:
GetPlayerName(playerid,name,sizeof(name)); and
GetPlayerName(playerid,name,MAX_PLAYER_NAME);
But what is the differences between them?

What effect does the sizeof() have on it?
Reply
#2

Quote:
Originally Posted by zack3021
Посмотреть сообщение
I have been using,
pawn Код:
GetPlayerName(playerid,name,sizeof(name)); and
GetPlayerName(playerid,name,MAX_PLAYER_NAME);
But what is the differences between them?
Try printing them.

pawn Код:
printf("%d",MAX_PLAYER_NAME);
printf("%d",sizeof(name));
Though i would recommend using an stock that returns the player name.. like this:

pawn Код:
stock GetPlayerNameEx(playerid)
{
     new pName[MAX_PLAYER_NAME];
     GetPlayerName(playerid, pName, sizeof(pName));
     return pName;
}
Reply
#3

Oh ok but what effect does the sizeof() have on it?
Reply
#4

None really, however it would be faster to just use the MAX_PLAYER_NAME definition since functions take longer to execute then simply reading numbers. For example,
pawn Код:
new pName[ MAX_PLAYER_NAME ];
GetPlayerName( playerid, pName, sizeof( pName ) );
// This is basically telling the compiler:
GetPlayerName( playerid, pName, sizeof( 24 ) );
Basically, making it run an extra function to do the same thing. So you are better off writing your code like so:
pawn Код:
PlayerName( playerid )
{
   new pName[ MAX_PLAYER_NAME ];
   GetPlayerName( playerid, pName, MAX_PLAYER_NAME );
   return pName;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)