[MAX_PLAYERS] or not?
#6

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
pawn Код:
new Variable;
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:
pawn Код:
new Var;
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:
pawn Код:
new Var[MAX_PLAYERS];
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.
Reply


Messages In This Thread
[MAX_PLAYERS] or not? - by jack3 - 27.12.2011, 12:51
Re: [MAX_PLAYERS] or not? - by kizla - 27.12.2011, 12:57
Re: [MAX_PLAYERS] or not? - by THE_KNOWN - 27.12.2011, 12:59
AW: [MAX_PLAYERS] or not? - by jack3 - 27.12.2011, 13:13
Re: [MAX_PLAYERS] or not? - by suhrab_mujeeb - 27.12.2011, 13:44
Re: [MAX_PLAYERS] or not? - by Ash. - 27.12.2011, 14:05
AW: [MAX_PLAYERS] or not? - by jack3 - 27.12.2011, 14:14

Forum Jump:


Users browsing this thread: 2 Guest(s)