Reloadable constants?

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
User avatar
tiko
New User
Posts: 14
Joined: Sat Mar 25, 2006 10:01 am

Reloadable constants?

Post by tiko »

Umm, I want to have a set of global variables that are re-loadable. Is this a poor way to do that?

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
The current contents of the reloaded config file (worldconst.cfg):

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
}
And in start.src (./scripts/start.src)

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
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.
User avatar
CWO
POL Expert
Posts: 1160
Joined: Sat Feb 04, 2006 5:49 pm

Re: Reloadable constants?

Post by CWO »

As long as you're setting it to a global property with SetGlobalProperty and the scripts that use the globals are using GetGlobalProperty and not reading the config itself, there should be no problem. Although I still can't understand why you would want to ApplyRawDamage to someone if it doesn't work...
Luth
Former Developer
Posts: 200
Joined: Mon Jan 30, 2006 8:10 am

Re: Reloadable constants?

Post by Luth »

CWO wrote:Although I still can't understand why you would want to ApplyRawDamage to someone if it doesn't work...
No mercy for the ignorant. Bwahahahaa! :D
User avatar
CWO
POL Expert
Posts: 1160
Joined: Sat Feb 04, 2006 5:49 pm

Re: Reloadable constants?

Post by CWO »

The start.src wouldn't even compile since the start wouldn't have a reference to 'who'. The beginning of the textcmd script does if (who.cmdlevel < 5) ... insert exploit stopper here (and no return?) and yet you can make this completely unneeded if you put it in the right folder... ect...

then again, I'm the type of person who would rewrite an entire script if I can cut 1-2 useless instructions from it.
User avatar
MontuZ
Forum Regular
Posts: 338
Joined: Fri Feb 10, 2006 8:08 am

Re: Reloadable constants?

Post by MontuZ »

I'm pretty sure he was using those as an example and not actually killing people if there was an error, lol.
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Re: Reloadable constants?

Post by Yukiko »

"I'm pretty sure he was using those as an example and not actually killing people if there was an error, lol."

Oh you're NO fun MontuZ!!!

*grins devilishly*
Post Reply