I am trying to set up a save system #223
Replies: 2 comments 5 replies
-
Just check this discussion #206 |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if you mean something like a save select screen as with discussion #206 or just the system, but for now I will cover the latter due to the usage of the word "system." One basic way to add saving itself is to use Godot's While I haven't checked if Worlds Next does this as well, one way I do this is to use dictionaries and iterate over them. I'd recommend doing this in an autoload script. First I declare a string that I can reuse for the save path: var save_path : String = "user://.data" Then, I create the save data variable. This variable is actually a dictionary, so manipulating it is the same as how you manipulate any regular dictionary. Each key in the dictionary is another dictionary, which contains certain variables and their values. In the context of this saving system, these top-level keys can be referred to as tables or sections. var data : Dictionary = {
"gameplay": {
"some_var": "super awesome"
},
"settings": {
"video_scale": 3,
"max_fps": 60
}
}
I first construct a var config_data : ConfigFile = ConfigFile.new()
# . . .
if config_data.load(save_path) != OK:
print("Creating save file")
save_data()
else:
print("Loading save file")
load_data() Two methods are defined. One is for saving the data, and the other is for loading the data. Both methods use iteration on func load_data():
for key in data:
for subkey in data[key]:
if config_data.has_section_key(key, subkey) == true:
data[key][subkey] = config_data.get_value(key, subkey)
save_data()
func save_data():
for key in data:
for subkey in data[key]:
config_data.set_value(key, subkey, data[key][subkey])
config_data.save(save_path) From this point, you can load and save data using If you need a screen to launch save files, then on that end I'm not exactly sure how to help. In my experience in using Godot, I've never implemented a save select screen, so I apologize on that end. |
Beta Was this translation helpful? Give feedback.
-
I don't think I am doing this correctly. Can someone explain how i can do this and does anyone have code for it?
Beta Was this translation helpful? Give feedback.
All reactions