How to make a proper working game save system

Hello once again all, so I was wondering about something. I wanted to make a gamesave option for my game, the primary reason would be to save my money that works like a score. Also maybe after beating a level and unlocking new levels to be saved.

So, how would this work exactly? I’m guessing you click a button and it writes a file containing the state that it was saved and then is created somewhere at the location of the game directory or data.

Again, the main thing I would like to be able to do:

  • Save my games money/score when playing
  • The game is the same on startup as saved before exiting from the previous session

Extra thing I would like (It would be nice to have):

  • Level gained after beating a level saved (Unlocked and still accessible for next time/session person wants to play)

Any assistance is appreciated, thank you for taking the time to read this post. :slight_smile:

As you said, you have to write in a file, the file is created in the main folder or a sub-folder of the game (in Preview mode, the file is created in the *.gdg file location). The action “Write a file” is in the section “Storage”.
You can save variable’s values, object’s positions, and another info with an “ID” name.
Then you can load the value from the ID name and save it in a variable.

For example, you have a variable Last_level, where you save the highest level you have reached for now. You can save it with the “Write file action”: Write Variable(Last_level) in “Highest level” of file “Save.txt”
Then load it when the game starts: Read “Highest level” from file “Save.txt” and store value in Variable(Last_level)
Now your variable reload its old value. “Save.txt” is the name of the file and “Highest level” is the “ID name” of the value, you can name both as you like.

There is a great example in the examples folder: “Level editor.gdg” :slight_smile:

You need all the necessary information from you game (Last level, score, options), save it in a file and then load it at start. :imp:

I recommend a level selection scene, with multiple objects “Scene_button”.
Each Scene_button with a variable “Level” from 1 to last level (for example 20).
Finally, a global variable “Last level”.
When you select a Scene_button, if you variable Last_level is equal or greater than the variable Level of the button, you can go to its scene. When you beat a level, if it is the last level, add 1 to the variable “Last level” :neutral_face:

Here is a little example: (3.53 KB)
Note: I use the value of the variable “Level” of each scene to compare with global variable Last_level, and for go to each button respective scene: Go to scene “Level_”+ToString(Scene_button.Variable(Level)). So, you don’t have to make one condition and action for each button.

Then, you only have to save the variable “Last_level”.