Unexpected behavior in INIFile.NumberedExists

More
11 years 6 months ago #19190 by SRC
Hello All,

I am coding a utility package that I hope will implement (and make generally accessible to modders who want to use them) the turret ship concepts introduced in Bineshi's delightful "Unleashed" mod.

Something odd has come up that I did not see in the Forum when I did a search on "NumberedExists".

It appears to me that

INIFile.NumberedExists(inifile, section, key, number)

returns "true" if there is a numbered key in the .ini file with the specified section and key and any number, not necessarily the number that you specify in the function call.

For instance, if you have a .ini file that does not have "null[]=" specified for every subsim (there is a template[]= key specified for every subsim, of course),

INIFile.NumberedExists(inifile, "Subsims", "null", i)

will return "true" for every value of i, including values of i for which there is not an explicit "null[]" entry in the .ini file.

I'm guessing that the INIFILE package assumes that the "missing" numbered keys are present for some internal reason that we cannot determine since we don't have the source code.

For my purposes, it would be nice to have a simple boolean function test for whether a numbered key is explicitly typed out in an .ini file, and so I have added this function to my iINIFileUtil.pog package that will accompany the utilities that implement unleashed features (and some US features)

//Doc Start
//Doc Header bool NumberedKeyHasDefinedValue(hinifile inifile, string section, string key, int number){
//Doc
//Doc Descr: Test a .ini file (opened with INIFile.Create) to see if the specified numbered key is explicitly
//Doc present with a defined value. If the key is not explicitly present in the .ini file or if it is
//Doc explicitly present but has no defined value, "false" is returned. If the key is explicitly
//Doc present and has a defined value, "true" is returned.
//Doc
//Doc NOTE ON USAGE: this can be used as an alternative to INIFile.NumberedExists(), which returns
//Doc true if any numbered key with the specified section/key values exists. This can be confusing
//Doc to the unwary POG coder who assumes that if the key is not present at the specified number
//Doc as seen in visual examination of a .ini file, then INIFile.NumberedExists() will return "false".
//Doc In fact, it returns "true" if the numbered key is present with any number.
//Doc
//Doc SRC 2012/10/02
//Doc
//Doc INPUTS (arguments)
//Doc
//Doc inifile hinifile the handle of the opened .ini file to test
//Doc section string the [Section] of the .ini file data structure to test
//Doc key string the key name to test
//Doc number int the number of the numbered key to test
//Doc
//Doc OUTPUTS (returned)
//Doc
//Doc is_defined bool "true" if the numbered key is explicity present in the .ini
//Doc file with a defined value
//Doc
//Doc Finish


bool NumberedKeyHasDefinedValue(hinifile inifile, string section, string key, int number){
string value;

value = INIFile.NumberedString(inifile, section, key, number, "");

if (value == "") return false;

return true;
}

Please Log in or Create an account to join the conversation.