polserver/docs/docs.polserver.com/pol100/cfgfileem.xml
turleypol 28556ecaf5
Appendcfgelem error (#358)
* added error check if file could not be opened for AppendCfgElem.

* added docs
2020-12-17 22:06:05 +01:00

291 lines
12 KiB
XML

<?xml version='1.0' encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="escript.xslt" ?>
<!DOCTYPE ESCRIPT SYSTEM "escript.dtd">
<ESCRIPT>
<fileheader fname="CFGfile.em">
<filedesc>Functions for accessing configuration files.</filedesc>
<datemodified>12/17/2020</datemodified>
</fileheader>
<function name="ReadConfigFile">
<prototype>ReadConfigFile(filename)</prototype>
<parameter name="filename" value="String (not including '.cfg')" />
<explain>Reads a given config file and returns a reference to it for use with other functions in this EM file.</explain>
<explain>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.</explain>
<return>A ConfigFileRef on success.</return>
<error>"Unable to find package X"</error>
<error>"Poorly formed config file descriptor: X"</error>
<error>"Config file not found"</error>
<error>"Invalid parameter type"</error>
</function>
<function name="FindConfigElem">
<prototype>FindConfigElem( config_file, key )</prototype>
<parameter name="config_file" value="ConfigFileRef" />
<parameter name="key" value="String or Integer" />
<explain>Finds a Config Element matching 'key' in the given config_file. In the following sample entry, 'applepie' is the key:
<code>
Dessert applepie
{
Cost 8
Calories 1004
MadeLike grandma
Ingredient flour
Ingredient butter
Ingredient apples
Deliciousness 3.6
}
</code></explain>
<return>A Config Element Reference on success</return>
<error>"Parameter 0 must be a Config File"</error>
<error>"Param 1 must be an Integer or a String"</error>
<error>"Element not found"</error>
</function>
<function name="GetConfigMaxIntKey">
<prototype>GetConfigMaxIntKey( config_file )</prototype>
<parameter name="config_file" value="ConfigFileRef" />
<explain>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.</explain>
<return>The maximum integer key in the file</return>
<error>"Parameter 0 must be a Config File"</error>
</function>
<function name="GetConfigStringKeys">
<prototype>GetConfigStringKeys( config_file )</prototype>
<parameter name="config_file" value="ConfigFileRef" />
<explain>Gets an array of all the String keys, AND integer keys (returned as strings) in the config file.</explain>
<return>An array of strings</return>
<error>"GetConfigStringKeys param 0 must be a Config File"</error>
</function>
<function name="GetConfigIntKeys">
<prototype>GetConfigIntKeys( config_file )</prototype>
<parameter name="config_file" value="ConfigFileRef" />
<explain>Gets an array of only all the Integer keys in the config file.</explain>
<return>An array of integers</return>
<error>"GetConfigIntKeys param 0 must be a Config File"</error>
</function>
<function name="ListConfigElemProps">
<prototype>ListConfigElemProps( element )</prototype>
<parameter name="element" value="ConfigElementRef" />
<explain>Gets an array of the element's property-names (as unique strings)</explain>
<return>An array of strings</return>
<error>"Invalid parameter type"</error>
</function>
<function name="GetConfigInt">
<prototype>GetConfigInt( element, property_name )</prototype>
<parameter name="element" value="ConfigElementRef"/>
<parameter name="property_name" value="String"/>
<explain>Gets a piece of Integer data from a config file element reference. For example, to get the value of 'Calories' in the following element:
<code>
Dessert applepie
{
Cost 8
Calories 1004
MadeLike grandma
Ingredient flour
Ingredient butter
Ingredient apples
Deliciousness 3.6
}
Use: 'var cals := GetConfigInt(element,&quot;Calories&quot;);'
</code></explain>
<return>An Integer value for the property</return>
<error>"Invalid type in config file! (internal error)"</error>
<error>"Property not found"</error>
<error>"Invalid parameter type"</error>
</function>
<function name="GetConfigReal">
<prototype>GetConfigReal( element, property_name )</prototype>
<parameter name="element" value="ConfigElementRef"/>
<parameter name="property_name" value="String"/>
<explain>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:
<code>
Dessert applepie
{
Cost 8
Calories 1004
MadeLike grandma
Ingredient flour
Ingredient butter
Ingredient apples
Deliciousness 3.6
}
Use: 'var yum := GetConfigReal(element,&quot;Deliciousness&quot;);'
</code></explain>
<return>An Real value for the property</return>
<error>"Invalid type in config file! (internal error)"</error>
<error>"Property not found"</error>
<error>"Invalid parameter type"</error>
</function>
<function name="GetConfigString">
<prototype>GetConfigString( element, property_name )</prototype>
<parameter name="element" value="ConfigElementRef"/>
<parameter name="property_name" value="String"/>
<explain>Gets a piece of String data from a config file element reference. For example, to get the value of 'MadeLike' in the following element:
<code>
Dessert applepie
{
Cost 8
Calories 1004
MadeLike grandma
Ingredient flour
Ingredient butter
Ingredient apples
Deliciousness 3.6
}
Use: 'var madelike := GetConfigString(element,&quot;MadeLike&quot;);'
</code></explain>
<return>An Real value for the property</return>
<error>"Invalid type in config file! (internal error)"</error>
<error>"Property not found"</error>
<error>"Invalid parameter type"</error>
</function>
<function name="GetConfigStringArray">
<prototype>GetConfigStringArray( element, property_name )</prototype>
<parameter name="element" value="ConfigElementRef"/>
<parameter name="property_name" value="String"/>
<explain>For elements with multiple occurrences of a given property, returns an array containing each occurrence.</explain>
<explain>For example, to get all the ingredients in the following element:
<code>
Dessert applepie
{
Cost 8
Calories 1004
MadeLike grandma
Ingredient flour
Ingredient butter
Ingredient apples
Deliciousness 3.6
}
Use: 'var ingredients := GetConfigStringArray(element,&quot;Ingredient&quot;);'
'ingredients' now contains 'flour', 'butter', and 'apples'.
</code></explain>
<explain>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.</explain>
<return>An array of strings.</return>
<error>"Invalid parameter type"</error>
</function>
<function name="GetConfigIntArray">
<prototype>GetConfigIntArray( element, property_name )</prototype>
<parameter name="element" value="ConfigElementRef"/>
<parameter name="property_name" value="String"/>
<explain>For elements with multiple occurrences of a given property, returns an array containing each occurrence.</explain>
<explain>Value of the properties are always returned as integers.</explain>
<return>An array of integers.</return>
<error>"Invalid parameter type"</error>
</function>
<function name="GetConfigStringDictionary">
<prototype>GetConfigStringDictionary( element, property_name )</prototype>
<parameter name="element" value="ConfigElementRef"/>
<parameter name="property_name" value="String"/>
<explain>Works similarly to GetConfigStringArray() but will take the first word on the line and use it for the key.</explain>
<explain>For example, to get all the ingredients in the following element:
<code>
Dessert applepie
{
Cost 8
Calories 1004
MadeLike grandma
Ingredient flour 1 kg
Ingredient butter 2 kg
Ingredient apples 3 kg
Deliciousness 3.6
}
Use: 'var ingredients := GetConfigStringDictionary(element,&quot;Ingredient&quot;);'
'ingredients' now contains ['flour'] = '1 kg', ['butter'] = '2 kg', and ['apples'] = '3 kg'.</code></explain>
<explain>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.</explain>
<return>Dictionary with Strings</return>
<error>"Invalid parameter type"</error>
</function>
<function name="AppendConfigFileElem">
<prototype>AppendConfigFileElem( filename, elemtype, elemkey, properties )</prototype>
<parameter name="filename" value="String"/>
<parameter name="elemtype" value="String"/>
<parameter name="elemkey" value="Int or String"/>
<parameter name="properties" value="Array of Arrays {propname,value}, or array of structs { name, value }"/>
<explain>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.</explain>
<explain>filename uses normal package descriptor format (see ReadConfigFile).</explain>
<explain>elemtype is the string before the key in the config file, i.e. 'MyType' in the following:
<code>
MyType 0x34F
{
MyProp 3.1
}
</code></explain>
<explain>elemkey is 0x34F in the above example. It can be a string or integer (as in that case)</explain>
<explain>properties must be an array of arrays with the following format:
<code>
var props := array;
var a := {&quot;MyProp1&quot;,1};
var b := {&quot;MyProp2&quot;,2};
props.append(a);
props.append(b);
AppendConfigFileElem( &quot;:mypkg:mycfg&quot;, &quot;MyType&quot;, 0x34F, props );
</code></explain>
<return>1 on success</return>
<error>"Unable to find package X"</error>
<error>"Poorly formed config file descriptor: X"</error>
<error>"Invalid parameter type"</error>
<error>"Failed to open file"</error>
</function>
<function name="UnloadConfigFile">
<prototype>UnloadConfigFile( filename )</prototype>
<parameter name="filename" value="String"/>
<explain>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.</explain>
<explain>Has no effect on most core-read config files like itemdesc.cfg, npcdesc.cfg, etc (See ReloadConfiguation in polsys.em)</explain>
<explain>filename uses the normal package descriptor format (see ReadConfigFile)</explain>
<return>Integer number of files unloaded</return>
<error>"Unable to find package X"</error>
<error>"Poorly formed config file descriptor: X"</error>
<error>"Invalid parameter"</error>
</function>
<function name="LoadTusScpFile">
<prototype>LoadTusScpFile( filename )</prototype>
<parameter name="filename" value="String, see explaination"/>
<explain>Very Old Function - may not work any longer!
<code>
//
// Load a TUS .SCP file as a config file
//
// Filename must be alphanumeric only. The file must exist
// in pol/import/tus. So LoadTusScpFile( "grayacct" ) will
// try to load "/pol/import/tus/grayacct.scp"
//
// Header properties, if any, in cfgfile[0]
// Other elements numbered sequentially from 1
// The part in brackets ("[WORLDITEM 04000]") will appear in two ways:
// 1) as a "_key" property
// 2) as a property itself (name=WORLDITEM, value=0x4000)
//
//
// So,if you had the following as the first element
// [WORLDITEM 04000]
// SERIAL=080
// P=1,2,3
// And 'var tusfile' was the result of LoadTusScpFile, then
// tusfile[1]._key is "WORLDITEM 04000"
// tusfile[1].worlditem is 0x4000
// tusfile[1].serial is 0x80
// tusfile[1].p is "1,2,3"
//
</code></explain>
<return>A Config File Reference</return>
<error>"Invalid parameter type"</error>
<error>"Filename cannot include path information or special characters"</error>
<error>"File not found"</error>
</function>
</ESCRIPT>