SA-MP Forums Archive
GetMaxPlayers() as a constant - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: GetMaxPlayers() as a constant (/showthread.php?tid=73221)



GetMaxPlayers() as a constant - Spectre - 13.04.2009

I've been interested in using the GetMaxPlayers() command as a constant, much like:

#define max_players GetMaxPlayers()
or
const max_players=GetMaxPlayers();

You know, so that I could build arrays based upon the server's limitations, like:
new doohickeys[max_players][3]
or something similar...

To me it seems logical that either should work but the first one just gives an error and the second causes a crash...

What is it that (in my advanced old age) has slipped through the cracks of my rapidly deteriorating grey matter? Some rule about constants I've overlooked?

Curious...



Re: GetMaxPlayers() as a constant - Donny_k - 13.04.2009

GetMaxPlayers() is returning a value and isn't an actuall value itself so the compiler sees it as a function call (not a constant) and not a value hence the hissy fit (crash).

You could always use #undef on the MAX_PLAYERS define then redefine it but I understand it's not what you want.