NobleEngine icon indicating copy to clipboard operation
NobleEngine copied to clipboard

using settings.setup with an empty dict results in bad data written to disk

Open foozmeat opened this issue 1 year ago • 3 comments

Steps:

  1. Open the Noble example project
  2. comment out the Difficulty line in Settings.Setup
  3. build & run it
  4. the game will crash
  5. Notice your settings.json file contains just []
  6. uncomment the Difficulty line
  7. 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.

foozmeat avatar Jul 15 '22 22:07 foozmeat

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 avatar Sep 06 '22 15:09 simjnd

@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!).

Mark-LaCroix avatar Sep 06 '22 23:09 Mark-LaCroix

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 {}?

simjnd avatar Sep 07 '22 05:09 simjnd

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.

Mark-LaCroix avatar Apr 02 '23 07:04 Mark-LaCroix