Save Settings from Different Scenes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By colonelkurtz

I’m building out a menu system (Godot 3) that uses a different scene for each menu screen. Currently I have one scene for Audio settings and another for Video settings. What would be the best way to save game settings to a file (and possibly any documentation on it)?

I’ve tried using a config file save, but if I change a Video setting, it rewrites the entire file, in effect removing any Audio settings I changed. The same is true visa versa. I then started working on a json file save, but I think the same is true, though haven’t gotten it to work 100%.

I’m trying to come up with creative ways to still use a config file (spent too long figuring out its implementation), but I welcome any hints on handling this more effectively.

An alternative solution that I haven’t tested: put everything on one scene with a scroll bar or something, and, upon scene close, gather all the values and save them to the file. While I haven’t tested this, I think this would also work for if the game crashes on the scene, since nothing would be saved until the “end” of the scene.

Would still be good to know if there is a good solution to my original question.

colonelkurtz | 2018-03-10 01:50

:bust_in_silhouette: Reply From: bitwes

My global (autoload) class holds all my settings. They are loaded from one or more config files at startup. There’s a method in there to write all the settings to a file. My various scenes that have settings in them call the global class’s save method to save all settings.

There’s really no other way to do it unless you want one file per type of settings. Settings tend to be global anyway so it’s not bad to load them up in the autoload. You can make a class that does it or have a bunch of hashes…the key is just to load them all in one place and save them all in one place.