Godot:ConfigFile
lastmod 2023-06-20created 2022-05-065 edits
How to create an INI-style config file
Config File Sample
It is an ini file like the following.
Save example
// Create new ConfigFile object.
var config = new ConfigFile();
// Store some values.
config.SetValue("Player1", "player_name", "Steve");
config.SetValue("Player1", "best_score", 10);
config.SetValue("Player2", "player_name", "V3geta");
config.SetValue("Player2", "best_score", 9001);
// Save it to a file (overwrite if already exists).
config.Save("user://scores.cfg");
Load example
var config = new ConfigFile();
// If the file didn't load, ignore it.
if (config.Load("user://scores.cfg") != Error.Ok) {
return;
}
// Iterate over all sections.
var data = new Dictionary<string, Variant>();
foreach (var section in config.GetSections()) {
data[section + ".player_name"] = config.GetValue(section, "player_name");
}
See also
- Godot
- Godot:SavingGames
- Godot:ConfigFile - Used for saving config files.
- Godot:PacketPeer - Binary serialization of packets
- Godot:ResourceSaver - Saves resource (
.tres) files.