neizarr wrote:
...
GetConfigPropertyNames(cfgelemref) which returns an array of the names of all the elements for that element reference.
...
GetConfigElemType(cfgElemRef) which returns a string, which is the type of the config element.
...
I thought it rather interesting that the first of those functions didn't exist already (as well as slightly disappointed) when I was scripting an in-game config-file navigator. I wanted to be able to display a config file as it appears in notepad, but had to settle. I definitely think that is a good idea.
The second one, however, I don't see as particularly useful. To my knowledge, the only text-files that care about datatypes in POL are datafiles. Config files don't use the datatype prefix unless you're dealing with CProps.
For example:
itemdesc entryCode:
CProp my_integer i52
would set a CProp named
my_integer with an integer value of
52 on the item upon creation.
Assuming that the need for knowledge of datatypes was absolutely imperative, however, I would take a look at basic.em's TypeOf().
TypeOf dictates that all available datatypes are:
Quote:
"Dictionary", "AccountRef", "ConfigFileRef", "ConfigElemRef", "DataFileRef", "DataElemRef", "ScriptExRef", "GuildRef", "BoundingBox", "DebugContext", "Package", "MenuRef", "MobileRef", "OfflineMobileRef", "ItemRef", "BoatRef", "MultiRef", "Unknown", "Uninit", "String", "Integer", "Double", "Array", "ApplicPtr", "ApplicObj", "Error", "Struct", "Packet"
Since it's a config file, you can immediately narrow that down to:
Quote:
"String","Integer","Double"
Considering that, testing for a datatype could be done as:
Code:
use cfgfile;
use basic;
function GetConfigElemType( byref cfgElem )
/*
* Use a string array, because you don't know how many
* values there are going to be for this entry.
*/
var elem_value = GetConfigStringArray(elem_value);
/*
* If the value has more than one entry, it can either be
* an array or a dictionary. For demonstration purpose, we'll
* ignore the idea of a dictionary. They're just specialized
* arrays anyways.
*/
if( len(elem_value) > 1 )
return "Array";
endif
/*
* If the value cannot be converted to an integer, it must be
* a string.
*/
if( !CInt(elem_value) )
return "String";
endif
/*
* If the value is not an array, and it is not a string, it must be
* either an integer, or a double. Since doubles have decimals, and
* integers do not, test it for a decimal point.
*/
if( elem_value["."] )
return "Double";
endif
/*
* If the value is not an array, string or double, then it must be an
* integer.
*/
return "Integer";
endfunction
I hope that's even slightly helpful.