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.
Best way to save game data
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!
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/
Thanks everybody!
- Edited
Saving and loading game data is an essential aspect of any game, and it's great that you thought about it early on. Godot has many ways to save and load game data, including JSON. However, the best method of saving/loading data will depend on your specific needs and game requirements. Another point is data security, as you should consider encrypting your data before saving it. On this website, you can also use a game platform that offers in-game services from professional players. They can help you with the data saving/downloading process and provide you with an effective and reliable solution.
cybereality The new link for recipes is https://kidscancode.org/godot_recipes/3.x/basics/file_io/