Read more than one value in a section [Config File]

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By J.B Stepan

I have a .cfg like this:


I want to get the values of all the Mod keys in the section, how do I do it?

While I’m not sure about the INI file implementation provided by Godot, most implementations will not allow a duplicate Key within the same section of the file.

So, for most INI readers, your example file isn’t even legal. Looking at the Godot docs on ConfigFile, it looks like the basic method for retrieving a given value is get_value which takes both a section name and a key name.

So, for your file, I’m not sure what you’d expect to get back if you requested the value for Section LoadedMods and Key Mod (since there are 2 Mod keys).

Bottom line, I’m not sure your file is even legal. And, even if it is, it seems like a less-than-ideal design.

jgodfrey | 2020-12-08 00:51

:bust_in_silhouette: Reply From: Calinou

Indeed, duplicate keys won’t work. Consider using an array instead:

Mods=["SomeMod", "AnotherMod"]

ConfigFile supports (de)serializing any Godot datatype, including arrays and dictionaries.