extends Node const DEFAULT_SETTINGS := { "username": "Giovanni", "character": 0 } var settings := DEFAULT_SETTINGS.duplicate(true) var server_url = "" var error_message = "" func _ready(): load_profile() func save_profile(): print("Save profile") var f = FileAccess.open("user://profile", FileAccess.WRITE) f.store_line(JSON.stringify(settings)) func load_profile(): # TOCTOU here. Godot docs says its fine. if not FileAccess.file_exists("user://profile"): print("Skip profile load") return print("Load profile") var f = FileAccess.open("user://profile", FileAccess.READ) settings = JSON.parse_string(f.get_line()) # Add missing keys for k in DEFAULT_SETTINGS.keys(): if !settings.has(k): settings[k] = DEFAULT_SETTINGS[k]