(SOLVED) Save file (Easy alternative)

Hi. Now, I know how to use the storage files (save and load, etc,) but I a, looking for something to make it a little easier. For example, instead of rewriting the same code, just load up an extension that allows you to save player position, level, score, and others, instead of separately saving each position, score, or whatever to separate locations manually. Are there any functions or behaviors like this?

Even if you used an extension, you’d still have to identify what data you want saved and where , and vice versa with loading the saved data.

A fairly easy way would be to create a structure, say called GameState, and under that have all the variables you want to save. To save them, convert GameState to JSON, and write it out. To load it, read in the JSON string and convert to the GameState variable. I think they can be done on one line each. I don’t know if it can get simpler than that (thought I’d love to find out a way that is)

1 Like

It’s easier than what I’ve been doing.
If that can be done on the same line, is there a way I can implement that line into a custom function? And then be able to change what the value’s name is, and which .JSON file it is being saved to?
Edit: Nevermind

Ok, it’s 2 lines to load - one to retrieve the data, and the next to parse and store it.

For anyone interested, to save to storage, something along the lines of:


And to load from storage, use something like:



Yep, the above is exactly how I do my game saves. There isn’t an easier way beyond using a structure variable as your main parameters and then parsing the save to/from it.

You can even do save slots this way, just make sure your structure has substructures of Slot1, Slot2, etc. Then within each slot you add all of your variables, and upon load you move all of that 1 slots variables over to the global variable, etc.

I use two slots in my save system for TripleJump to create a “transactional” save system that prevents corruption in the case of an interrupted save. Basically it uses a slot A and a slot B stored in a separate meta data storage that only indicates whether the current slot A or B. When data is saved it fully writes the save data into storage into the other slot, then it updates the meta data to point to the slot it just saved to. This ensures that you always have a backup copy of the previous save data, and if your program ever gets interrupted while saving the data the pointer to the current slot won’t be updated because that happens only once the save is complete.

Sorry, I realize after typing this, that I’ve drifted far away from the “Easy save file” topic. In general though, using the structure to JSON functions is definitely the way to go.


This actually helps a lot
I will be using this from now and on, because the way I have been doing it is a mess lol

Hi, I found your explanation very interesting. Could you please share a screenshot of the save system?

I do not understand if it is necessary to save twice, or only once in an alternating manner.

Thanks in advance and I’m sorry I replied to an old topic!

It’s not too complicated… the trick is that you don’t save the “slot” pointer until you are done saving the data in that slot. So if the data saving is interrupted, the slot pointer will still point to the previous save.