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.