NobleEngine
NobleEngine copied to clipboard
using settings.setup with an empty dict results in bad data written to disk
Steps:
- Open the Noble example project
- comment out the
Difficulty
line inSettings.Setup
- build & run it
- the game will crash
- Notice your
settings.json
file contains just[]
- uncomment the
Difficulty
line - build & run
The game still crashes. It looks like changing settings to contain {}
fixes the problem and avoids the "new key" issue I mentioned on discord.
This could perhaps be better reflected in the docs, but currently NobleEngine doesn't support adding keys to settings that weren't present upon setup (more concretely: Noble.Settings.set("myKey", "myValue")
won't do anything if Noble.Settings.setup
wasn't given a dictionary with a "myKey" as a key).
This means that if you don't give Noble.Settings.setup
a dictionary with keys, you won't be able to use Settings
at all, so you wouldn't call the setup
method in the first place.
Is there a use-case for adding settings at runtime that aren't known at load-time? I can't think of any.
You could workaround this limitation by using GameData
, maybe choose a save slot that is dedicated to those things.
@simjnd's PR that I just pulled does a good job of clarifying this issue, but I do still think I need to add better handling for situations like this (not everyone reads the docs!).
Makes sense, currently get
and set
bonk (throw bonks?) if the setting being read/written does not exist. We could add a check in setup
and bonk if __keyValuePairs
is nil
or {}
?
Now that #40 is merged, I think I can mark this as resolved. Feel free to open a new issue if there is another angle on this topic that wasn't covered.