Learning to Script, Can someone explain this in English. -
Dokins - 11.05.2011
Arrays
Scope
I do not understand these aspects. Can someone explain them to me clearly in a way that I would understand?
AW: Learning to Script, Can someone explain this in English. -
Nero_3D - 11.05.2011
https://sampwiki.blast.hk/wiki/Scripting_Basics
Click on the section arrays, dont know what you mean with scope
Re: Learning to Script, Can someone explain this in English. -
steki. - 11.05.2011
arrays are indexed varaiables.
this let you use inumerous vars in the same name.
Think an array as a nightstand, you create it with the name "array" and you put 10 drawers.
That means.
new array[10];
So, you have.
array[0] = 312938;
array[1] = -23432;
array[2] = 45118;
that way (:
Re: Learning to Script, Can someone explain this in English. -
Sasino97 - 11.05.2011
This is declaring an array:
It's easier doing
instead of
pawn Код:
new a1;
new a2;
new a3;
new a4;
new a5;
new a6;
new a7;
new a8;
new a9;
new a10;
You can use the array in this way:
pawn Код:
a[4] = 100;
//instead of
a4 = 100;
You can add to array slot names using the enum
pawn Код:
enum info
{
pMoney,
pScore,
}
new pInfo[MAX_PLAYERS]/*WICH IS 500*/[info];
//instead of
new pMoney[MAX_PLAYERS];
new pScore[MAX_PLAYERS];
Using MAX_PLAYERS, its also using an array, because:
pawn Код:
//Because it declares an array with 500 slots (MAX_PLAYERS is 500 by default)
new Score[MAX_PLAYERS];
//DOES
new Score0; //The score of the player ID 0
new Score1; // '' ''
new Score2;
new Score3;
new Score4;
new Score5;
new Score6;
new Score7;
new Score8;
new Score9;
new Score10;
new Score11;
// [...] TO Score500;
Every number is the ID of the player in the server.
When you use "playerid" in the callbacks like OnPlayerSpawn, playerid means "The ID of the player that spawned"
So arrays are indexed variables
Re: Learning to Script, Can someone explain this in English. -
Rafa - 11.05.2011
one question why we are putting MAX_PLAYERS on "Player Money"
which is the task they perform ?? о_0
new pMoney[MAX_PLAYERS];
Thanks.
Re: Learning to Script, Can someone explain this in English. -
Sasino97 - 11.05.2011
Because it must contain the money of all the players.
Money of player ID 0
Money of player ID 1
Money of player ID 2
Money of player ID 3
Money of player ID 4
[...]
When a player connects to a server, he gets an ID, wich it's the ID that counts the players.
The first to enter is ID 0
If other 2 players come their IDs are 1 and 2.
if ID 1 leaves in the server there are only ID 0 and ID 2
and when a new player connects his ID will be 1 and not 3, because 1 is missing.
Re: Learning to Script, Can someone explain this in English. -
steki. - 11.05.2011
If when you declare an array, you put the number of slots, and as the sa-mp maximmum is 500, you use one index to each player.