Level: Beginner
Saving Games
Saving progress is a fundamental part of most games. This article explains how our saving system works.
Contents
-
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 your Game Attributes and replace them with the values of those in the save file.
Saving and Loading are 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)

That's it!
Detecting Failure
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.
Note: Don't use the save/load succeeded blocks outside the scope of the save/load wrapper, or you'll run into a compile-time error.
Where is Data Saved?
Flash games use Local Shared Objects. That is to say, it's stored by the browser indefinitely until cleared out.
iOS games store save data directly on the file system using CoreData. This data is not deleted until the game itself is deleted (and settings/data are explicitly told to be removed).
Summary
-
Saving is based on Game Attributes.
-
Loading will overwrite all Game Attribtues.
-
Saving/Loading is an instant operation.
Challenge: Checkpoints
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.
Last Updated: 2012-04-03 by Jon
13200 have read this article
Disclaimer: The Stencyl Team does not actively monitor comments on articles. If you're seeking help for your game,
please ask a question on the forums. Thanks!
Sign In to Comment