MAX_PLAYERS
#1

what's the difference if we do the following:

pawn Код:
#define MAX_PLAYERS GetMaxPlayers()
instead of:

pawn Код:
#define MAX_PLAYERS (YOUR AMOUNT HERE)
i was thinking about it but i have no idea about that.
Reply
#2

You can put "#define MAX_PLAYERS" as 500000
While GetMaxPlayers() is the amount of slots the server has.
Reply
#3

First, you should understand that
pawn Код:
#define useless exemple
create a macro, meaning "useless" will be replaced by "exemple" everywhere in your script when you'll compile it (in fact, it happens a bit before the compile itself).

Second, GetMaxPlayers() will read the number of slots from the server config (server.cfg) thought 500 is a constant number.

So, you can't use GetMaxPlayer() to define an array size because it should be a constant number.

So, best you have to do is using
pawn Код:
#define MAX_PLAYERS 500
but using foreach() for your loops.

PS: Sorry for my bad english :-'
Reply
#4

Array sizes have to be specified at compile time, which GetMaxPlayers can't do because it is variable (it can vary).
Reply
#5

#define replaces something with something else.

So the only difference is:

pawn Код:
#define MAX_PLAYERS GetMaxPlayers()

new Score[MAX_PLAYERS];
would compile as

pawn Код:
new Score[GetMaxPlayers()];
and

pawn Код:
#define MAX_PLAYERS 500

new Score[MAX_PLAYERS];
would compile as

pawn Код:
new Score[500];
Try "Show preprocessed output" in PAWN Playground
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)