Best way to save game data

Hi!
I want to make my game save the player's data, and I was searching how to do it. It seems that Godot has many ways to save and load game data, including using (or not) JSON.
My question is: Is there is a best method to save/load data?
Like, some methods may be limited, or may be inneficient.
So, I would like to know your opinions to the best one to an Android game.
Thx.


Tags :

Comments

  • Erich_LErich_L Posts: 590Member

    I can't speak for android, but if you wanna keep things in easy to read for godot I suggest using a resource file. This is mine for saving a level of my tile-based game.

    class_name SaveGame
    extends Resource
    
    export var game_version : String
    export var floorTiles : Array
    

    Look how short and sweet!

    Then for using it to save:

    var savegame := SaveGame.new()
    savegame.game_version = ProjectSettings.get_setting("application/config/version")
    
    for c in floorNode.get_children():
        savegame.floorTiles.push_back(c.save())
    
    var path = "res://Levels/Level_" + String(activeLevelNo) + ".res"
    var err = ResourceSaver.save(path,savegame)
    if err != 0:
        print("error saving game in Level Editor, code: ", err)
    

    Then you can go back to eating Turkey!

  • cyberealitycybereality Posts: 3,714Moderator

    See here for a robust and recommended way to do it:
    https://docs.godotengine.org/en/stable/tutorials/io/saving_games.html

    But if you just need to save a few variables, this is easier:
    https://kidscancode.org/godot_recipes/basics/file_io/

  • UpsetChickenUpsetChicken Posts: 18Member

    Thanks everybody!

Sign In or Register to comment.