define/variable
#10

Quote:
Originally Posted by DowNlOaD_
Quote:
Originally Posted by Kyosaur!!
Quote:
Originally Posted by DowNlOaD_
i mean something like this
pawn Код:
#define MAX_PLAYERS               PlayersOnline()
and PlayersOnline() returns the number of players on server
You cant really do it like that due to one thing: Arrays. Functions can not be used outside of callbacks, so if any MAX_PLAYER arrays are declared globally, it'll crash the compiler.

You could go like:

Код:
#if defined MAX_PLAYERS
	#undef MAX_PLAYERS
#endif

#define MAX_PLAYERS 150
Which would make loops a lot faster, and would cut down on ram ussage (providing you dont use pvars). But thats as far as it goes tbh.


EDIT: Ohh i see what you meant, i thought you meant redefine MAX_PLAYERS to the GetMaxPlayers() value. My fault lol.
ok thanks everybody, and i knew about that #define MAX_PLAYERS 150

and at least PlayersOnline() works in loops

PS: when i'm doing something like that: new VAR[PlayersOnline()]; it crashes my pawn compiler
You CAN NOT use your PlayersOnline for a loop, the reason being:

Lets say you HAD 50 players... 0-46 disconnect for some unkown reason. You are left with players 47,48, and 49. You're variable says there are 3 players online (which is true) but when you loop, it'll go 1..2..3 and what ever your doing for the players in that loop WILL NOT reach the connected players.

The best way for efficient looping is a redefinition of MAX_PLAYERS like the one above, but that can get to be a pain due to having to edit when ever you switch you max players value in your server.cfg

Код:
for(new i=0, p=GetMaxPlayers(); i<p; i++)
{
  //stuff
}
Код:
thats the way to do it, if your looking for the most efficient dynamic way.



OFF TOPIC:

As for your "new VAR[PlayersOnline()];" statement, i told you: You CANT use functions outside of callbacks.
Reply


Messages In This Thread
define/variable - by DowNlOaD_ - 16.06.2010, 18:45
Re: define/variable - by (SF)Noobanatior - 16.06.2010, 18:47
Re: define/variable - by Kyosaur - 16.06.2010, 18:49
Re: define/variable - by DowNlOaD_ - 16.06.2010, 18:54
Re: define/variable - by (SF)Noobanatior - 16.06.2010, 18:57
Re: define/variable - by DowNlOaD_ - 16.06.2010, 18:59
Re: define/variable - by (SF)Noobanatior - 16.06.2010, 19:02
Re: define/variable - by Kyosaur - 16.06.2010, 19:02
Re: define/variable - by DowNlOaD_ - 16.06.2010, 19:07
Re: define/variable - by Kyosaur - 16.06.2010, 19:14

Forum Jump:


Users browsing this thread: 2 Guest(s)