There can be many possible problems when we do a save system, since it's not just about saving basic stats like HP or something.
For a complex game world, a save system may get a little bit complicated. So, for saving basic informations, like HP, we use json. These information can be stored in a dictionary, and when we save the game, we simply save the dictionary into a file. When we load, we update the infos inside the dictionary according to what is saved inside the file. This is the simpler part. However, we can make the dictionaries be more useful for saving more complicated infos. Example: {"Info_Type": "Character Attribute", "Character_path": PATH, "attribute": ATTRIBUTE}
For saving other things like players position, enemies killed, current level of the scene, spawing points, etc. These kinds of infos can actually also be saved into a dictionary or array.
For example, for the enemies that are dead, when loading the game, we want them to be deleted so it will be just like the time before when you saved the game. We can use a array like: dead_enemies
, whenever you killed an enemy, append something like this into the array: {"Info_Type": "Dead Enemy", "Node_path": PATH}
. When save the game, save each of them into your file. When load the game, using for loop iterating every line, if Info_Type
is "Dead Enemy", use get_node(LINE.Node_path).free()
SImilar to other different situations. When save, we can use one more layer that contains extra infos that help to identify what is being saved instead of just a dictionary of attributes so it will be convenient when load.
For a character, use a dictionary to save all the attributes and status instead of tons of seperated single variables so it will be good when it comes for saving the game. Also, try to have a function save()
for each objects you want to save (You may want to use "group" to keep in track of which objects are the ones you want to save) and a function save_game()
that collects all the saved infos returned from the functions save()
from all the objects in the group.
For things like attacking, just use variables to decide current status, and use variables of boolean or string to determine what characters can do. This will help to change status and update things, also it will be convinent for saving since they are variables and simple variables can be saved into a dictionary.