How to make game save?

I’m trying to make saving for my game now that I have all the levels and cutscenes done. What I want to save (for now) are three global boolean variables. WorldBeaten1, WorldBeaten2 and WorldBeaten3. Simply it would save after a world has been beaten so the player can return playing the game and doesn’t need to beat a world they have already beaten.

The game has a hub part where it checks if a global boolean variable is true or false. If it’s true it will let the player continue to the next world. Now how do I save this so it can check it after the game is closed and reopened?

I got some type of saving to work but what happens is that the game somehow changes all the WorldBeaten booleans to true after pressing the load save button even if I would only have beaten world 1 and by then only toggled the World1Beaten boolean to true not all 3 of them.

This is the code for when it should save and then change to the hub. WorldBeaten1 global boolean variable has been toggled to true before this event. (The code is the same for the other WorldBeaten booleans but in later parts of the game)

This is the code for loading the save files.

This is the code for deleting the save file. I think it should be correct.

Hi there, if you will check your second image you will see that you are loading level1 information into level 2 and level 3 because you are using the same Convert JSON string TemporaryVariable into World2variable and World3variable. Not even sure you have to convert bools to strings to save them, I usually did them as numbers but who knows with the new variable stuff.

Still it might be better to eventually switch to one number global variable WorldBeaten with a default value of 0 and every time the player completes a level, use a condition to check if the current world number is greater than the WorldBeaten global and if so change the global to the current world number and save to storage. In the hub scene, check if the file exists in storage and if so, load it into global WorldBeaten. For the buttons/images that lead to different worlds, if their button/image variable World is equal or less than global WorldBeaten+1, unlock them for the player.

1 Like

I got the saving to work properly thanks to you pointing out the mistake in the second image but for some reason after changing it to say “TemporaryVariable1”, “TemporaryVariable2” and “TemporaryVariable3” the deleting save data broke. It refuses to delete the “PainterBlazer” storage for whatever reason even though it work before. The game only restarts if I reopen the game and don’t press the load button on the title screen.

Any idea what could have caused this?

No not really from what you’ve shown, but you don’t show all actions related to your save logic here. For instance you show saving something and changing to scene Hub but you don’t show turning the variable you’re saving to false or true.

What is supposed to happen when you delete the storage? You say the game only restarts (resets the levels?) when you reopen the game but I don’t see any actions, in the place where you delete the storage, to change the global boolean variables back to default value (false I assume).

Also unrelated but as a pointer you have variable systems mixed up. VariableString(NameOfVariable) is part of the old system. Now you just say NameOfVariable. As is GlobalVarToJSON(NameOfGlobalVariable). Now you just say ToJSON(NameOfGlobalOrSceneVariable). In actions you can type value to find change variable value (general not object) and then in the Value field of the text variable you have selected type ToJSON and pick the non object one.

And also for anyone in the future, you can also just save a boolean variable as a number and the engine knows 0 is false 1 is true.