Home › Forums › Mods and POG Scripting › Unexpected behavior in INIFile.NumberedExists
- This topic has 0 replies, 1 voice, and was last updated 12 years, 1 month ago by SRC.
-
AuthorPosts
-
3. October 2012 at 7:49 #15832SRCParticipant
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 Finishbool NumberedKeyHasDefinedValue(hinifile inifile, string section, string key, int number){
string value;value = INIFile.NumberedString(inifile, section, key, number, “”);
if (value == “”) return false;
return true;
} -
AuthorPosts
- You must be logged in to reply to this topic.