godotengine / godotengine/godot-docs
User store_var instead of JSON in the savegame tutorial
- Dominant language
- reStructuredText
- Stars
- 5.7k
- Forks
- 3.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 25
Description
**Your Godot version:** 4.0 beta 1
**Issue description:** Using JSON as a serializing format introduces many errors that might be non obvious from the warnings in the docs.
**URL to the documentation page (if already existing):** https://docs.godotengine.org/en/latest/tutorials/io/saving_games.html?highlight=serialization#saving-and-reading-data
"Saving Games" uses `save_game.store_line(to_json(node_data))` and `parse_json(save_game.get_line())`. This introduces many issues:
__Not really human readable or debuggable__
The latest docs claim it's easier to read and debug. That would be the case if the whole savegame where stored as prettified json object, which is easy to read and modify. In the example we get many json objects, each in one line, making it harder to read. The user might also prettify them by mistake, breaking the file. Same thing if anything is rearranged.
__Only one number format__
JSON only has one number type and when parsing everything is converted to TYPE_REAL. This is mentioned in the docs but the implications are hard to predict and I've seen many people get bitten by conversion issues.
A really nasty one and hard to predict is enum comparison. `if 1.0 == 1` evaluates to `true` but `match 1.0:` doesn't match for `1` which might make it seem random and hard to debug.
__Proposal__
Use `store_var` and `get_var` in the tutorial. Beginners will probably copy paste it so it's best to give them something that will give them the fewest headaches. I personally use just one dictionary, with a version number for easy conversion and then as many internal dicts/arrays/etc. for all my data. It means you only need to call store_var and get_var once and you can have things like settings, inventory, etc be a key in the dict, so you don't need to worry about matching each store_var with a get_var in the same order.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.