The CFGFILE function module defines the following functions:
A configuration file consists of zero or more elements. Each element has a type, a key, and zero or more properties. At present, the key must be a positive integer. A sample file can be found at the right. It contains two elements, with different keys. The element type for each is BowcraftData. This is currently neither used nor accessible. The first element's key is 0x1BD4; the second's is 0x13B2. The properties for each are contained within the curly braces. All property names and values are treated as strings; CInt() must be used to convert to numeric if appropriate. The examples are assumed to access this file. |
CONFIG/BOWCRAFT.CFG
|
ReadConfigFile | |
Declaration: | ReadConfigFile( filename ); |
Function: | Reads a configuration file from the config/ directory. |
Returns: | Zero if configuration file does not exist, or has errors. A handle to a config file if the file was read successfully. |
Notes: | Do not include path information or ".cfg" in the filename. |
Example: | Global cfile; cfile := ReadConfigFile( "bowcraft" ); if (cfile) // do stuff with the configuration file endif |
FindConfigElem | |
Declaration: | FindConfigElem( config_file, key ); |
Function: | Search a configuration file for an element by key. |
Returns: | A handle to the element if found. Zero if the element could not be found or if config_file does not refer to a valid configuration file handle. |
Example: | Local elem; elem := FindConfigElem( cfile, 0x1BD4 ); if (elem) // do stuff with the element. endif |
GetElemProperty | |
Declaration: | GetElemProperty( element, property_name ); |
Function: | Retrieve a property value from a configuration element. |
Returns: | The property value if the property value exists. Zero if the property did not exist or element is not a valid configuration file element. |
Notes: | The value returned is a string; CInt() must be used to convert this
to a numeric value if appropriate. The property_name parameter is case-insensitive. |
Example: | Local materials, difficulty, pointvalue; materials := CInt(GetElemProperty( elem, "Materials" )); difficulty := CInt(GetElemProperty( elem, "Difficulty" )); pointvalue := CInt(GetElemProperty( elem, "PointValue" )); |