File: CFGfile.em
Description: Functions for accessing configuration files.
Last Modified: 10/27/2007
AppendConfigFileElem( filename, elemtype, elemkey, properties ) | |
---|---|
Parameters: | |
Name | Type |
filename | String |
elemtype | String |
elemkey | Int or String |
properties | Array of Arrays {propname,value}, or array of structs { name, value } |
Explanation | |
Appends an element to the config file specified. Properties must be an array of structures, where each element is a structure containing a name member first, and a value member second. | |
filename uses normal package descriptor format (see ReadConfigFile). | |
elemtype is the string before the key in the config file, i.e. 'MyType' in the following: | |
MyType 0x34F | |
elemkey is 0x34F in the above example. It can be a string or integer (as in that case) | |
properties must be an array of arrays with the following format: | |
var props := array; | |
Return values | |
1 on success | |
Errors | |
"Unable to find package X" | |
"Poorly formed config file descriptor: X" | |
"Invalid parameter type" |
FindConfigElem( config_file, key ) | |
---|---|
Parameters: | |
Name | Type |
config_file | ConfigFileRef |
key | String or Integer |
Explanation | |
Finds a Config Element matching 'key' in the given config_file. In the following sample entry, 'applepie' is the key: | |
Dessert applepie | |
Return values | |
A Config Element Reference on success | |
Errors | |
"Parameter 0 must be a Config File" | |
"Param 1 must be an Integer or a String" | |
"Element not found" |
GetConfigInt( element, property_name ) | |
---|---|
Parameters: | |
Name | Type |
element | ConfigElementRef |
property_name | String |
Explanation | |
Gets a piece of Integer data from a config file element reference. For example, to get the value of 'Calories' in the following element: | |
Dessert applepie | |
Return values | |
An Integer value for the property | |
Errors | |
"Invalid type in config file! (internal error)" | |
"Property not found" | |
"Invalid parameter type" |
GetConfigIntKeys( config_file ) | |
---|---|
Parameters: | |
Name | Type |
config_file | ConfigFileRef |
Explanation | |
Gets an array of only all the Integer keys in the config file. | |
Return values | |
An array of integers | |
Errors | |
"GetConfigIntKeys param 0 must be a Config File" |
GetConfigMaxIntKey( config_file ) | |
---|---|
Parameters: | |
Name | Type |
config_file | ConfigFileRef |
Explanation | |
Gets the value of the highest value integer key in the config file. This is useful if all the keys are sequentially numbered and need to be looped over. | |
Return values | |
The maximum integer key in the file | |
Errors | |
"Parameter 0 must be a Config File" |
GetConfigReal( element, property_name ) | |
---|---|
Parameters: | |
Name | Type |
element | ConfigElementRef |
property_name | String |
Explanation | |
Gets a piece of Real (float) data from a config file element reference. For example, to get the value of 'Deliciousness' in the following element: | |
Dessert applepie | |
Return values | |
An Real value for the property | |
Errors | |
"Invalid type in config file! (internal error)" | |
"Property not found" | |
"Invalid parameter type" |
GetConfigStringArray( element, property_name ) | |
---|---|
Parameters: | |
Name | Type |
element | ConfigElementRef |
property_name | String |
Explanation | |
For elements with multiple occurrences of a given property, returns an array containing each occurrence. | |
For example, to get all the ingredients in the following element: | |
Dessert applepie | |
Value of the properties are always returned as strings. If the values are ints or reals, use CInt() or CDbl() to cast the values to the correct type. | |
Return values | |
An array of strings. | |
Errors | |
"Invalid parameter type" |
GetConfigStringDictionary( element, property_name ) | |
---|---|
Parameters: | |
Name | Type |
element | ConfigElementRef |
property_name | String |
Explanation | |
Works similarly to GetConfigStringArray() but will take the first word on the line and use it for the key. | |
For example, to get all the ingredients in the following element: | |
Dessert applepie | |
Value of the properties are always returned as strings. If the values are ints or reals, use CInt() or CDbl() to cast the values to the correct type. | |
Return values | |
Dictionary with Strings | |
Errors | |
"Invalid parameter type" |
GetConfigString( element, property_name ) | |
---|---|
Parameters: | |
Name | Type |
element | ConfigElementRef |
property_name | String |
Explanation | |
Gets a piece of String data from a config file element reference. For example, to get the value of 'MadeLike' in the following element: | |
Dessert applepie | |
Return values | |
An Real value for the property | |
Errors | |
"Invalid type in config file! (internal error)" | |
"Property not found" | |
"Invalid parameter type" |
GetConfigStringKeys( config_file ) | |
---|---|
Parameters: | |
Name | Type |
config_file | ConfigFileRef |
Explanation | |
Gets an array of all the String keys, AND integer keys (returned as strings) in the config file. | |
Return values | |
An array of strings | |
Errors | |
"GetConfigStringKeys param 0 must be a Config File" |
ListConfigElemProps( element ) | |
---|---|
Parameters: | |
Name | Type |
element | ConfigElementRef |
Explanation | |
Gets an array of the element's property-names (as unique strings) | |
Return values | |
An array of strings | |
Errors | |
"Invalid parameter type" |
LoadTusScpFile( filename ) | |
---|---|
Parameters: | |
Name | Type |
filename | String, see explaination |
Explanation | |
Very Old Function - may not work any longer! | |
// | |
Return values | |
A Config File Reference | |
Errors | |
"Invalid parameter type" | |
"Filename cannot include path information or special characters" | |
"File not found" |
ReadConfigFile(filename) | |
---|---|
Parameters: | |
Name | Type |
filename | String (not including '.cfg') |
Explanation | |
Reads a given config file and returns a reference to it for use with other functions in this EM file. | |
Note, takes the usual package filespec: '::cfgfile' is in /pol/config, '::regions/cfgfile' is in /pol/regions, ':*:cfgfile' is a combination of all configs named 'cfgfile' in all pacakages, and ':pkgname:cfgfile' is a specific cfgfile inside a package. If only 'cfgfile' is passed, POL looks for it first in /pol/config and then in each package sequentially. | |
Return values | |
A ConfigFileRef on success. | |
Errors | |
"Unable to find package X" | |
"Poorly formed config file descriptor: X" | |
"Config file not found" | |
"Invalid parameter type" |
UnloadConfigFile( filename ) | |
---|---|
Parameters: | |
Name | Type |
filename | String |
Explanation | |
Unloads a config file from memory. If other scripts reference the config file specified, it will remain in memory until they no longer reference it. Scripts which call ReadConfigFile() after this, however, will re-read the config file and use the newer version. | |
Has no effect on most core-read config files like itemdesc.cfg, npcdesc.cfg, etc (See ReloadConfiguation in polsys.em) | |
filename uses the normal package descriptor format (see ReadConfigFile) | |
Return values | |
Integer number of files unloaded | |
Errors | |
"Unable to find package X" | |
"Poorly formed config file descriptor: X" | |
"Invalid parameter" |
If you know if any information is incorrect on these pages, mail your corrections to polteam@polserver.com
Copyright ©2003-2006 David Carpman and POL Development Team, all rights reserved. DO NOT REPRODUCE, MIRROR, ALTER, SPINDLE, MUTILATE, OR SIT ON.