by Jon (Updated on 2014-01-26)
Saving progress is a fundamental part of most games. This article explains how our saving system works.
- How Saving Works
- How To: Saving and Loading
- Detecting Failure
- Where is Data Saved?
- Challenge: Checkpoints
How Saving Works
Saving in Stencyl uses a game’s Game Attributes to save data.
All you have to do is structure your game such that anything you want to save is stored in Game Attributes.
Similarly, loading a save file will completely overwrite the game's current Game Attributes and replace them with the values of those in the save file.
Saving and Loading are nearly instant - these operations will not hang your game. That said, Saving and Loading are blocking operations in the sense that nothing else will happen until those operations are complete.
How To: Saving and Loading
Saving and Loading involve just use these two blocks. (Game > Saving)
When do you load a game? It's up to you, but most like to do it in the game's first scene.
What do the save succeeded and load succeeded blocks do? That's detailed next.
Occasionally, a player will be unable to save, usually due to restrictive security settings.
If saving/loading fails, you can detect this and use the “save succeeded” and “load succeeded” blocks react appropriately, such as showing an error message.
To use them, just drag them out as pictured and use them within an if-block.
Where is Data Saved?
Flash games use Local Shared Objects. That is to say, it's stored by the browser indefinitely until cleared out.
Mobile games store save data directly on the file system but within the confines of the app's sandbox. This data is not deleted until the game itself is deleted (and settings/data are explicitly told to be removed). At this time, it isn't possible to specify custom save locations or write out arbitrary data at runtime.
- Saving is based on Game Attributes.
- Loading will overwrite all Game Attribtues.
- Saving/Loading is an instant operation.
Many games use a checkpoint system, a system in which reaching a certain part of the level will guarantee that, if a player dies, the player can continue from that checkpoint, rather than starting from the beginning.
Create a simple checkpoint system for your game, such that even if the player exits out of the game, he’ll begin from the last checkpoint he reached.