cfgfile::GetConfigValue()

Archive of the older Feature Request Forum Posts
Locked
User avatar
ncrsn
Grandmaster Poster
Posts: 255
Joined: Fri Feb 10, 2006 12:15 am

cfgfile::GetConfigValue()

Post by ncrsn »

We already have GetConfigInt, GetConfigReal and GetConfigString. What would GetConfigValue do?

Same thing as configelemref.key - that is, analyze and choose the type of the value before it is copied to variable, instead of converting it into a string.

This is useful when scripter does not know the structure of config file element the script will parse.

Code: Select all

// example.cfg
configelem example
{
    key1    text
    key2    193
    key3    31.1
}

Code: Select all

var elem := ReadConfigFile("example")["example"];

foreach key in ListConfigElemProps(elem)
    // array{ "key1", "key2", "key3" }
    // There's no way to read the correct values (at least, without trial-error).
   // GetConfigString(elem, key); is safe solution but is not suitable if values are later to be used "blindly".
   // elem.key does not work because it is read as elem."key"
   // GetConfigValue(elem, key), if existed, would return
   // "text", 193 and 31.1.
endforeach
I hope this explains it.
Locked