Simple beginner question
#1

Hello guys.
Im a beginner at scripting, and im trying to learn more.
I have seen a lot of scripts using this:
pawn Код:
new something[MAX_PLAYERS];
Where "something" is called something else.
That is this, and why are they using "MAX_PLAYERS"?

Hope someone can tell me what it is. Thank you.
Reply
#2

This is called a variable. It can store numbers in it, and when using [x] after it, you can store multiple numbers in a single variable. This is called an array.

I suggest using ****** or something for more information.
Reply
#3

Okay. So MAX_PLAYERS is defined as a number somewhere?
Reply
#4

Yes, it is defined in the a_samp.inc include provided with the default SA-MP server package, in the latest SA-MP server package, it is defined as 500. So what you're really writing is

pawn Код:
new variable[500];
This creates an array with 500 writable cells, the last cell is used for the null termination character.

Each cell can store an integer or a single character, so you may also be able to use arrays as strings, however in this case, this type of array is usually used in SA-MP for storing things per player. For example:

pawn Код:
public OnPlayerConnect(playerid)
{
    variable[playerid] = playerid * 2;
    return 1;
}
So whenever you refer to the variable, you can refer to a certain cell by playerid which is storing a value, in this case, the variable stores that playerid's ID multiplied by 2, so if your ID is 10, that variable will contain 20. This is how we generally make variables to store temporary information for each player.

I hope that helps.
Reply
#5

Thank you very much for your help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)