Skip to content

Godot:ConfigFile

INI스타일의 설정파일 제작 방법

Config File Sample

다음과 같은 ini파일 이다.

[section]
some_key=42
string_example="Hello World!"
a_vector=Vector3( 1, 0, 2 )

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

Favorite site