Reloadable constants?
Posted: Wed Aug 20, 2008 9:48 pm
Umm, I want to have a set of global variables that are re-loadable. Is this a poor way to do that?
The current contents of the reloaded config file (worldconst.cfg):
And in start.src (./scripts/start.src)
Without killing a script's process ID (I want to begin the rehash at start.src and with a command), I would think that reloading the custom variables from here would be safest. Simply using global properties to it's fullest extent, from the beginning, should prove useful. No, I didn't RTFM. Sorry, I like beer, too.
Code: Select all
use cfgfile;
include "include/utils"
program dotcmd_reloadconst(who, text)
if (who.cmdlevel < 5)
send_to_gm("Idiots have tried to use .reloadconst!");
SendSysMessage(who, "GO DIE!");
ApplyRawDamage(who, 99999);
else
UnloadConfigFile(":worldconst:worldconst");
var cfg := ReadConfigFile(":worldconst:worldconst");
var elem := FindConfigElem(cfg, "global");
var props := ListConfigElemProps(elem);
// props variable is an array of all global "constants" we are going to reload. (not their values).
var value;
foreach constant in (props)
value := GetConfigString(elem, props[constant]);
// i could either iterate through another bit of shit here to determine if we have 'string' or 'int' values, or i could just force int use in the config. :)
if (TypeOf(value) != "Integer")
SendSysMessage(who, "THAT DIDN'T WORK!");
ApplyRawDamage(who, 99999);
endif
SetGlobalProperty(props[constant], value);
endforeach
endif
endprogram
Code: Select all
# This file contains variables used by scripts unloadable by the core that may need alteration at any given point to obtain a result without restart.
global global
{
WORLD_SPAWN_TIME_MINIMUM_SECONDS 1800
WORLD_SPAWN_TIME_ADDITIONAL_RANDOM_MINUTES 20
}
Code: Select all
// load the world constants, simplified boot time version of command .reloadconst
var cfg := ReadConfigFile(":worldconst:worldconst");
var elem := FindConfigElem(cfg, "global");
var props := ListConfigElemProps(elem);
// props variable is an array of all global "constants" we are going to reload. (not their values).
var value;
foreach constant in (props)
value := GetConfigString(elem, props[constant]);
// i could either iterate through another bit of shit here to determine if we have 'string' or 'int' values, or i could just force int use in the config. :)
if (TypeOf(value) != "Integer")
SendSysMessage(who, "THAT DIDN'T WORK!");
ApplyRawDamage(who, 99999);
endif
SetGlobalProperty(props[constant], value);
endforeach