Saving means writing important information from the game to a file (Such as player position and health)
Loading means restoring that information into the game
Add Save and Load buttons to your level
then change the text property
Save and Load Utility Node
Create a new scene with Node as the root
Attach a Script to the node
Create a function to save the game
Create a function to load the game
Add the SaveAndLoad scene to your level scene
Connect the pressed function of the SaveButton
To the save_game() function
Select the save_game() function
Connect the pressed function of the LoadButton
To the load_game_function()
To save to a file we need a new file
Note that: user:// is is a folder that is always writable
Now that we have a file to store data
Let's try storing the position of the Player
Since a game usually only has one player, we can make the node name reference unique
Add reference variables for the player
by holding CTRL and dragging the node into the code
Use the store_var function of file
to store the global position of the player
Open the file you want to load
For a very simple game or only saving one variable such as a high score this simple approach works just fine!
Important note: If you want to store more than one value such as player position and player health etc.
The variables must be saved and loaded in the same order!
The main issue with this approach is that we cannot save dynamically created objects