- Edited
hi guys.. this is my autoload code for save/load of some settings for characters. as you can see it is a simple one, the problem is when i set the name or color, i see changes in game, but nothing changes in config file. so when i restart the game, it return to its default value, how can i change values/name in config file that when i restart the game i see the effects in the game not just the default values? thank you :)
extends Node
const SAVE_PATH = "res://settings.cfg"
var config_file = ConfigFile.new()
var stored_info = {"color": {"body_color1": Color(1,1,1,1), "body_color2": Color(0,0,0,1)}
,"player_info":{"player_name": "Some Dude"}}
func _ready():
save_settings()
load_settings()
func save_settings():
for section in stored_info.keys():
for key in stored_info[section].keys():
config_file.set_value(section, key, stored_info[section][key])
config_file.save(SAVE_PATH)
func load_settings():
var error = config_file.load(SAVE_PATH)
if error != OK:
print("Failed Loading Settings File. error code %s" % error)
return[]
for section in stored_info.keys():
for key in stored_info[section].keys():
stored_info[section][key] = config_file.get_value(section, key, null)
print("%s: %s" % [key, section])
return[]
func get_setting(category, key):
return stored_info[category][key]
func set_setting(category, key, value):
stored_info[category][key] = value
for ex. i use
get_node("/root/global").set_setting("color", "body_color1", Color(0,1,0,1))
for changing character's skin to green and it works in game, but nothing changes in config file