Raised This Month: $51 Target: $400
 12% 

Global array set to a variable size


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Saxywolf
Junior Member
Join Date: Feb 2008
Old 03-06-2008 , 14:46   Global array set to a variable size
Reply With Quote #1

I'm trying to make a few arrays that should be at least as big as the number of players. I could just use a constant so high that I doubt there would be a server with that many people (64?), but that would be a waste of memory and not really proper.

Note: I'm not error checking to see if the number of max clients is changed, and I don't care.

Code:
94: new Server_Max_Players = GetMaxClients() +1
...
104: new Float:gPlayerSwitchedTeam[Server_Max_Players]
105: new gGrieferTeam[Server_Max_Players]
106: new String:gGrieferClientID[Server_Max_Players][64]
107: new gBlocksUnfrozen[Server_Max_Players]
108: new Float:gTimeOfLastUnfreeze[Server_Max_Players]
However, I get errors:
Quote:
freezestatus.sp(94) : error 010: invalid function or declaration
freezestatus.sp(94) : error 008: must be a constant expression; assumed zero
freezestatus.sp(104) : error 008: must be a constant expression; assumed zero
freezestatus.sp(105) : error 008: must be a constant expression; assumed zero
freezestatus.sp(106) : error 008: must be a constant expression; assumed zero
freezestatus.sp(107) : error 008: must be a constant expression; assumed zero
freezestatus.sp(108): error 009: invalid array size (negative, zero or out of bounds)
if I use "#define Server_Max_Players = GetMaxClients() +1;" I don't get the line 94 error, but I still get the others as error 029's: invalid expression (as well as new ones later on). Does this actually set the variable to get the number of max clients each time it is called?

Is there a way to do what I want in a proper way?
Saxywolf is offline
sfPlayer
Senior Member
Join Date: Dec 2007
Location: Germany
Old 03-06-2008 , 15:55   Re: Global array set to a variable size
Reply With Quote #2

You can't define dynamic arrays outside a local scope, use adt_array instead.
sfPlayer is offline
pRED*
Join Date: Dec 2006
Old 03-06-2008 , 18:26   Re: Global array set to a variable size
Reply With Quote #3

However adt_array is slower than normal memory. Generally it's better just to define the array as MAXPLAYERS+1 and you'll always be fine. It's really not much memory to waste (65*4 = 260kb = 0.26mb = shit all).

If you want large arrays of strings for each player then adt_array is probably a good choice.
pRED* is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:34.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode