MAX_PLAYERS
#1

Hi, it's me again. ;p
I have another question(like usually).
When I have in my GM something like this:
Код:
#undef MAX_PLAYERS
#define MAX_PLAYERS NUMBER_OF_MY_SLOTS
and my question is simple.
How I must use this?
like:
Код:
arena[playerid] == true
or
Код:
arena[MAX_PLAYERS] == true
or
Код:
arena[NUMBER_OF_MY_SLOTS] == true
Greetings, micol.
Reply
#2

playerid is a default variable in most callbacks which need one players' id to proceed.
if you ever try to access a variable with [MAX_PLAYERS], you will get no warning/error at compile time, but the script will crash, due to an "out of bounds error".
hence each array starts at an index of 0 - assuming 80 MAX_PLAYERS, the 80'th element gets assigned [79].
when declaring an array with 80 slots, is IS required to use the size of 80.
here is a little example:
Код:
new Test[MAX_PLAYERS]; //array ranging from 0 upto MAX_PLAYERS-1 (79), is 80 cells together.
later, in a function/callback USING playerid, like:
Код:
public OnPlayerUpdate(playerid)
{
	new Test[playerid]=GetTickCount();//writes the actual timestamp into the playerid's cell.
	return 1;
}
here a loop in a function, NOT using playerid, so it needs to be created first:
Код:
stock Timestamps()
{
	for(new playerid=0;playerid<MAX_PLAYERS)
	{
		Test[playerid]=0;//delete timestamp for each player
	}
	return 1;
}
Reply
#3

Thanks for quick answer.
I'm finally know this. : D

Greetings, micol.

@EDIT

And another edit from my side. : c

Can you tell me whether I can write code like this:

Код:
new arena[2][MAX_PLAYERS]
or how ?

This means something like this
Код:
arena[0][playerid] == 1
arena[1][playerid] == 1
Reply
#4

Quote:
Originally Posted by micol
How I must use this?
like:
Код:
arena[playerid] == true
or
Код:
arena[MAX_PLAYERS] == true
or
Код:
arena[NUMBER_OF_MY_SLOTS] == true
not sure what Babul hasn't mentioned, but MAX_PLAYERS is just a number. So it doesn't really matter in the above ^. But be weary! #defines are used (and should be used) when wanting to make multiple references towards some value. it becomes a compile-time constant meaning before actual compilation (preprocessing) all occurrences of the identifier are replaced with a constant value. hi, click me.

Quote:
Originally Posted by miloc
Can you tell me whether I can write code like this:

Код:
new arena[2][MAX_PLAYERS]
or how ?

This means something like this
Код:
arena[0][playerid] == 1
arena[1][playerid] == 1
yes...
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)