How to check if a value in a SAVE file (config) exists??? HELP

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

I have errors comming up when app is run for the first time because it says that no default value was given. How should i check if value exist or give a default value?

func _loadsingletons():
if config.get_value(“Settings”, “Sound”) != null:
singletons.sound = config.get_value(“Settings”, “Sound”)

:bust_in_silhouette: Reply From: njamster

The (optional) third argument of get_value is the default value. “If default is not specified or set to null, an error is also raised.” (Source) A warning would be more appropriate here in my opinion, but as of now you’ll need to do something like this:

const DEFAULT = -1
if config.get_value("Settings", "Sound", DEFAULT) != DEFAULT:
    singletons.sound = config.get_value("Settings", "Sound")

Thank you so much for solution! I fixed all errors with it and I hope that now my game wont crash on some very sensitive platforms. Thank you once again for your time :slight_smile:

buxnast | 2020-05-29 19:59