A little question about name variable.
#1

Is it ok if i create a local variable for getting 2 player's name like this?
pawn Код:
new Name[2][24], target;
GetPlayerName(playerid, Name[0], 24);
GetPlayerName(target, Name[1], 24);
Can it bug the name of the player or something?

I have been thinking about it but didn't attempt to test without knowing. So can anyone tell me if its ok?
Reply
#2

I think it doesn't matter. Haven't really tried it before through, rather wait for someone who has.
Reply
#3

So which method is good to prevent the local variables from consuming data? My gamemode size has kinda increased and i was thinking if its because of creating too many variables. I have most of the local variables created like "new Name[24], AdminName[24]" to get the names of 2 players. So i was guessing that may be the reason for huge code size?
Reply
#4

Quote:
Originally Posted by ******
Посмотреть сообщение
As for using "name[2]" instead of "name0" and "name1", for data that size there is no good reason to use an array instead of two variables, and in fact the resulting code is larger and slower.
So you should use a variable and not an array.
Reply
#5

Quote:
Originally Posted by Faisal_khan
Посмотреть сообщение
So you should use a variable and not an array.
It's really upto you. Making an array always wastes memory but you can also make a char-array if the value doesn't needs to be greater than 255 or lower than 0. Normal array stores values between -2,147,483,648 and 2,147,483,647, so you don't really need it.

pawn Код:
new var[2 char];
// Now we will use var{0} var{1} like this with braces.
Reply
#6

Ok, thank you.
Reply
#7

Why not use a stock to get a player's name?
For example :
pawn Код:
stock Name(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    return name;
}
Now use Name(playerid) or Name(killerid) or anyother thing to get the specific names where you want.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)