0 votes

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")

in Engine by (46 points)
edited by

1 Answer

+1 vote
Best answer

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")
by (10,265 points)
selected by

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 :-)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.