- Home /
Save / Load multiple stages
Hey guys,
I have a small question...
Consider the following mobile game: - Players can purchase multiple books - Each book contains up to 30 pages - Each page contains a type of minigame with a unique progress as well as a score which gets calculated upon completion.
If I want to create a save / load funtionality now what is the beste approach, having a single save game data that save all the data or having individual save games for each book or even every single page ?
Answer by Bunny83 · Sep 22, 2020 at 01:15 PM
That's entirely up to you. Each approach has some advantages and disadvantages. The most robust solution is of course using seperate files for each "stage" / minigame, especially if the data is quite unique to each minigame. I haven't really worked with iOS but on android you can also create subfolders in the private space dedicated for your app. So you can make a savegame folder with a sub folder for each book and have a single file for each stage / minigame.
By more robust I mean when you have everything in one file, if anything goes wrong when saving, the file might get corrupted and all is lost. Also having everything in one file increases the number of data that has to be written / rewritten to disc whenever you want to update the save state. So you would probably even do the flash memory of your users a favor.
Of course having multiple seperate files makes it a bit more difficult if you need to work on all data at once. Though it's also possible to seperate plain highscores from the actual saved gamestate. Since you calculate the score only once on completion it probably would make sense to store it in a single file.
Note that there is almost never a one-size-fits-it-all solution. The choice which approach you want to use depends on many factors. Specifically:
how much data does each minigame has that need to be saved?
how often do you wish to save the state? (once a second?, once every minute?, once every session?)
How much of that data is later used at once? So is the gamestate only relevant for each minigame besdes the final score?
I would most likely use json as save format for several reasons. It can essentially store any kind of data structure, so it's relatively easy to adapt for each minigame. It also makes debugging much easier as you can read and test modify the saved data easily. Of course I would probably use my SimpleJSON framework as it would allow me to easily switch between a single save game file or seperate files.
Keep in mind if you are worried about players cheating by modifying the save files, you can never prevent that, only make it a bit harder. With json as save format you can add a simple encryption / scrambling once you're done testing to give script kiddies a hard time :)
ps: One way to scramble any data is putting it through my Huffman encoder. It might even end up being slightly smaller ^^. The great thing is that once huffman encoded it has no trace of the original text. A custom implementation like this makes it a bit harder to "unscramble". Just using base64 or zipping the data are common approaches which many recognise and can reverse.