OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Surdus Priest on 13 Dec 2007, 18:34:10
-
how many global variables can you get away with?
-
Also remember lots of user-created addons create new global vars - depending on, of course. Then again, this is supposed to be fixed in 1.09.... :dry:
Wolfrug out.
-
If it's possible in your case, you could try to reduce them by using loadFile and nil to get at data and to destroy it when it's not needed anymore. This could work if you have constant data which is not dynamically changed. Such data would not be necessary to keep loaded all the time.
-
how many global variables can you get away with?
ArmA < 1.09: 240, IIRC
Arma >= 1.09...who knows. If it's really fixed, then "a high number".
Meanwhile, a possible solution to get around GV namespace pollution and overpopulation: use setVariable and getVariable on an object of your choosing (perhaps a game logic):
Example:
// init.sqf
// Create a GL to use for variable storage
KLS_MyVars = "Logic" createVehicleLocal [0,0,0];
// Create two utility functions
KLS_fSet = { KLS_MyVars setVariable _this };
KLS_fGet = { KLS_MyVars getVariable _this };
Then, use the utility functions like this:
["count",3] call KLS_fSet;
...
...
_count = "count" call KLS_fGet;
hint format ["Count is currently %1",_count];
Yes, it's cumbersome. :D
-
I had the too many global variables problem with the first beta version of Punishment Battalion. Ultimately it helped me edit and write scripts better though and imroved the mission. I reduced overall lag by constantly deleting old triggers, objects, variable names etc. I think i ended up with about 50 global variables and then the saved game works. But at 200 i had problems.
see this quick tutorial:
http://www.ofpec.com/ed_depot/index.php?action=details&id=413&page=0&game=ArmA&type=tu&cat=xyz
also everytime i use a variable and know i don't need it again, i render the variables nil as Baddo mentioned:
Tank1 domove getmarkerpos "Destination"
~2
tank1 = nil
deletemarker "destination"
destination = nil
exit