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.