[MAX_PLAYERS] or not? -
jack3 - 27.12.2011
I ask myself everytime i call a new variable what i have to use.
When do I have to use something like this:
pawn Код:
new Variable[MAX_PLAYERS];
or when I should use:
It would be helpful if someone could explain that to me. :)
PS.: Sorry if a thread like this exists, but i didnt find it.
Re: [MAX_PLAYERS] or not? -
kizla - 27.12.2011
When you use MAX_PLAYERS you use variable as Variable[playerid], and is for a player, and if you dosent it is global variable...
Re: [MAX_PLAYERS] or not? -
THE_KNOWN - 27.12.2011
if you want to save something thats related to each player individually then use [MAX_PLAYERS].
eg: when u wanna save each players money
Money[playerid] = GetPlayerMoney <== his money will be saved to his playerid slot of Money var
if you want to save something thats common for all like max player count, use new variable;
Im a troll in explaining -.- but i know how to use them
AW: [MAX_PLAYERS] or not? -
jack3 - 27.12.2011
thx for the fast help. =)
Re: [MAX_PLAYERS] or not? - suhrab_mujeeb - 27.12.2011
If you want the variable to be for a special purpose for example if you want it to be used by the server or by only one client then you go with
If you want it to be used by every player or some other purposes for example using it for more than one purpose you go with
pawn Код:
new Var[MAX_PLAYERS]; // or
new Var[size];
I know I can't explain good.
Re: [MAX_PLAYERS] or not? -
Ash. - 27.12.2011
Quote:
Originally Posted by suhrab_mujeeb
If you want the variable to be for a special purpose for example if you want it to be used by the server or by only one client then you go with
If you want it to be used by every player or some other purposes for example using it for more than one purpose you go with
pawn Код:
new Var[MAX_PLAYERS]; // or new Var[size];
I know I can't explain good. 
|
Correct, I'll expand on it though as your description is slightly vague.
Declaring a variable such as:
is simple a single variable. You can only store a single piece of data in this variable (without messing about with binary and stuff).
Declaring a variable as:
is called an array. An array can store multiple pieces of data related in 'slots' relative to the array itself. It's a little like doing:
pawn Код:
new Var1;
new Var2;
new Var3;
new Var4;
new Var5;
//etc...
(but, it uses slightly less memory if I remember correctly).
You can access (and set) data from/to an array by knowing the 'slot'. This could be stored in a variable or otherwise. Example:
pawn Код:
Var[playerid] = 1; //Where playerid is declared as an integer.
//Make Var[playerid] become 1.
pawn Код:
Var[0] = 0;
//Make the slot 0 of var equal to 0.
pawn Код:
for(new i; i < sizeof(Var); i++) //In this example, "sizeof(Var)" gets the array size.
{
Var[i] = 100;
}
//This loop will make all the slots in the array called "Var" equal 100.
I hope you can understand better now.
AW: [MAX_PLAYERS] or not? -
jack3 - 27.12.2011
Quote:
I hope you can understand better now.
|
Yes I do, now. thanks a lot for all help =)