Skip to content

User store_var instead of JSON in the savegame tutorial #6249

Open
@noidexe

Description

@noidexe

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:manualIssues and PRs related to the Manual/Tutorials section of the documentationenhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions