I have been watching all tutorials about saving game progress, and thought I understood, but am completely lost again. I understand you have to save variables. But…there’s a lot going on in my game that doesn’t make use of variables. For example: change animation to, change position, show/hide object. How can I save this information? Do I have to create a variable for each action and then save each of those variables? Seems lika tremendous lot of work…or maybe I did all of my programming wrong as a complete beginner?
The only way to save game progress between sessions (as far as I am aware) is through storage. How you do it is you hit Save “example” in storage, then you can load it in and run events after loading it.
Why do all the intricate details need to be saved? Usually all that’s saved are things like score, lives, current level and maybe checkpoint/last position.
But not animation, visibility etc. Unless there’s a specific reason for it.
Pretty much yes
There is no variable for position of your player
You set position X and Y to some variables then save these variables
And when you load game you load these variables and set position of your player to these variables
And that goes also for saving animation or object state
You literally create variables for every type of info you care to save
However you can automate process more or less after you create such vars
It’s an escape room, so if a closet has been unlocked and opened (changed animation), I would like it to stay that way. Maybe I didn’t programm the inventory the right way, because I just move the object to a certain position and make it draggable, but didn’t use an actual inventory-system…maybe that way it will use variables?
And if I delete an object, how can I put that into a variable?
There’s no player-character, lives, score etc. Only objects that interact with others, locks with codes.
I’d suggest you use a structure variable, and store the information you want saved in that, using the object name as the key and the data to save as the children. Then, using the idea from @SnowyRawrGamer’s reply, save the structure to storage.
The painting has to stay this way. But how do I put this into a variable? And this has to happen for a lot of pieces of the painting. Do I have to make a variable somehow for each part?
If all the pieces of the painting get tweeted to invisible at the same time, you should be able to set it so when they use the brush, it sets a variable “BrushUsedOnPainting1” to true & save that to storage. Then when you need to load it, you could check if that was in storage, and automatically set all the parts of the painting to invisible.
I grouped the parts of the same color of the painting, but they are painted independently. Not sure if I could make a variable for the whole group, will try it out.
Ok, some things are finally saving and loading, very happy about that! But not sure I’m doing this the easiest way. Since I have to save lots of parts of the painting, I tried saving a light being turned on first. Is this the shortest way of doing that?
You seem to be using Global Variables. Is that what you meant by saving & loading instead of storage?
In that case, yes that is a very simple way to do it.
If you are wanting to save between sessions, then you will need to use storage. Global variables reset themself when the app is closed and re-opened.
That works, but my issue now is to put every object (for example parts of the painting) in storage. I’m wondering if there’s an easy way to make variables for all of them. They don’t have exactly the same actions. There’s 5 colors and all of them contain different parts. I made an action for a group of colors, this works on still painting them seperately. But when I try to make a variable for the group, they get colored all at once. Not sure if my babbling makes any sence to you?
Hi jastrid …I’ve edited this a bit …if you want all your variables that you need to save in the same global structure variable. Like ‘savedata’.
This could contain other structures which themselves contain arrays which could contain structures…here is structure/structure/array/structure
Savedata.saveobjects.paintings[12].colours.‘255,255,255’
That could be used to get the colour of painting 12
All the data in savedata can go as a json to storage but needs to come back via a scene text variable.
When saving…a series of ‘repeat for each object’ or repeat for each object in a group could be used to fill the database. If the objects are all on the editor to start with. This repeat event could to refer to a unique id number that you’ve given them. use a scene variable that counts up after storing each object and will store each in the array child with that number.
If there is a save file…you then need to read the saved data at the beginning of the scene using repeat events and adjust the position and colour etc of the various objects. You could do this for all the objects in an object group or treat the object types all individually…it depends how varied the information about them is.
As an edit here …if you don’t want to number things in the editor as there’s hundreds of objects you can do this
Beginning of scene
If there is a save file - delete everything and create objects in repeats events that read the database of objects and positions animations etc
When player saves or exits …read the objects on the editor into a database and number them here.
here’s some of the structure that i used for my game ‘harelines’ The user can create levels that are stored in ‘builder’ - they have their own save data here and it stores the position and animation of all the objects on the editor.
Wow, I literally understand like 10% of this
I get the part of saving and loading, but the repeat thing is Arabic to me…probably need someone te stand beside my desk and explain in dummy language (which this probably already is )
I guess I just add every variable manually, but…
I can’t seem to save scene variables in a JSON file…at least not in the same storage. Am I missing out on something here?
If I get time …I’ll try and explain it better…I’m not the best at explaining stuff!
Get all those scene variables in a global structure and then save them to storage as a json in one go. In the example above all the data does just that
Hi, it works now when I save the scene variables in a different group as the global variables. Not sure why and how I would have to put them in a global structure then?
More and more things work out, but then the next problem rises. Trying to put current animation into a variable and store/load it. I followed all instructions, but the animation resets every time. Any ideas?
I capture the current animation frame of my main character using Sprite(). I save the current frame to a number variable. I sometimes delete and immediately recreate my character, so I use the anim frame when he was deleted to set the frame of the new instance, so it’s seamless to the player (trevorLarge is my object name in this example). If I wanted to include in a save file the character’s animation frame at the time of saving, I’d use the same global variable to do it.