As of late 2021, we are in the process of updating Stencylpedia and fixing up outdated & broken content. Thanks for your patience!

70,975

Views

Beginner

Level

18

Comments

Saving Games

by Jon (Updated on 2015-10-18)


Contents

  • Overview
  • How To: Saving and Loading
  • Where is Data Saved?
  • Challenge: Checkpoints

Overview - Saving uses Game Attributes

Saving progress is a fundamental part of most games. Our saving system 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.

Saving

Similarly, loading a save file will overwrite the running game's Game Attributes and replace them with the values of those in the save file. For this reason, it's best to load a save file as early as possible.

How To: Saving and Loading

Usage

Saving and Loading involve these two blocks. (found under Game > Saving)

Saving Blocks

What happens when the save/load block is used?

  1. The game attempts to save / load. This is quick (nearly instant), but the game will not progress until the save / load operation is complete or has failed.

  2. When the save is complete (or has failed), the body (inside) of the block will run.

  3. save succeeded / load succeeded will be true if saving/loading succeeded. Otherwise it will be false.

We talk more about how to handle failure next.

Handling Failures

Sometimes, a player will be unable to save due to restrictive security settings or other reasons.

If saving/loading fails, you can detect this and use the save succeeded and load succeeded blocks to react appropriately, such as showing an error message.

Handling a failed save

To use them, just drag them out as pictured and use them as you see fit.

Warning: 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.

When should loading happen?

There's no hard rule for this, but for most games, doing it early on in the game's first scene makes sense. Remember again that loading will overwrite the game's game attributes.

Common Question: Playing the game for the first time.

Suppose that the player is playing your game for the first time. How do you know this? You could create a game attribute called "first time" that is initially set to true. When you save the game, it's set to false, so that when the game is loaded up again, that flag will now always be false.

Where is Save Data saved?

It depends on the platform.

Flash

Flash games use Local Shared Objects. That is to say, it's stored by the browser indefinitely until cleared out.

iOS / Android / Desktop

Mobile games store save data directly on the device's file system but within the confines of the app's sandbox. This means that the data is "safe" and cannot be tampered with by any other apps.

This save data is not deleted until the game itself is deleted (and settings/data are explicitly told to be removed).

Note: At this time, it isn't possible to specify custom save locations or write out arbitrary data at runtime.

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 automatically begin from the last checkpoint he reached.

Print Article Edit Article How to Edit an Article
Disclaimer: Use comments to provide feedback and point out issues with the article (typo, wrong info, etc.). If you're seeking help for your game, please ask a question on the forums. Thanks!

18 Comments

Chris24XD
l have an idea for checkpoints: Some games have some passwords for keeping the game saved. You can make a custom save and load it with password.
0 4 years, 5 months ago
Chris24XD
Does Stencyl also saves the customable controls?
0 4 years, 5 months ago
Chris24XD 2
@mikhog Did you check everything??? (and if you doing this with controls, better change it with a button (Actor))
0 4 years, 5 months ago
Chris24XD 2
@Franca Uy Dude, it's just a custom block. You can use a print block to do this. While you testing you're game oen log viewer, save the game and see which message will appear to you.
0 4 years, 5 months ago
Franca Uy
hi, where can i find the display message block? thanks!
-1 4 years, 5 months ago
Chris24XD 2
It works at me!!
Question:
How can you save by an ID Number???
Anyone know???

0 4 years, 6 months ago
jaimoc
que pasa si quiero publicar el juego en flash, pero sin subirlo a Internet. ¿esto funcionara?
-1 4 years, 10 months ago
cvaughn55
Fyi Display Message isnt a block in stencyl anymore

1 8 years, 2 months ago
Piquinim
Hi i'm tryng to do a save when pressed ctrl S but i want to when my characters dies it will revive in the same location i have doed ctrl S any know how?

-1 9 years, 7 months ago
guicamarotto
to make checkpoint, create a game attribute, name it as checkpoint or anything else, and make a region in different parts of your game that you want to be a checkpoint. so, when de player actor reach a sensor, set the attribute to a number related to that specific region, and call the save propertie.

on the load event, program to the actor be created at the checkpoint that your saved game attribute says that is the last checkpoint reached.

1 10 years, 1 month ago

Sign In to Comment