What a Save Game Must Hold: Facts, Not Where You Stand

The demo is playing itself. Press a key or a button to take over.
The save starts after 3 seconds without a change, never while a wasp is in the room, and at once when she walks out of the door. A failed save waits 5 seconds before the next try, then 10, then 15, up to 30.
Try it: Pour again while the bee is still flying: the chest gets the old number, and a second save follows, because your new honey was not in the first. Lock the chest and watch each failed try wait longer. Keep pouring without a pause: after 60 seconds it saves anyway.
Space pour honey X walk out (quit) ↓ lock or unlock the chest
A save has to hold what the player did, not only where they stand. This lesson finds what a load must give back on the game above, where a chest keeps a beekeeper's work. Then your AI tests a save taken in the middle of a quest, and an old save loaded after the story changed.
Also in this lesson 5 things to read up on 3 questions to check yourself
The idea
A save is a promise: close the game now, and the story will be where you left it. So the list of what a save holds is not a new list. It is the facts, quest states and character numbers you already wrote down in this course, and the place where the player stands is one more line at the bottom.
What a save leaves out matters just as much. The scene on the screen, a line half said, a cutscene that is running: the game draws them again from the facts. A save that keeps the scene keeps the part that is easiest to rebuild, and forgets the part that cannot be rebuilt at all.
Play the game above for a minute first. The beekeeper pours honey in her workshop, and the chest in the corner is the save.
How it works
Read the two numbers. The number at the top left is what she has done: every spoon of honey poured. The number over the chest is what the last good save holds. If the game crashed now, a load would give back the chest's number and nothing else. Pour a few spoons and stop. After 3 seconds without a change, and with no wasp in the room, a bee carries the number to the chest, and the two numbers agree again.
Look at what is not in the chest. The full jars on the shelf and the honey in the jar under the tap are not saved. The game works them out from the one number, so a load that gives back the number gives back the shelf as well. Where she stands is not in the chest, and neither is the wasp. That is the line between a fact and the scene: a fact is what the game cannot work out again, and the scene is drawn from the facts.
Pour again while the bee is flying. The chest gets the old number, and a second save follows a few seconds later. The bee carries a copy taken at the moment it set off, so a save is all the facts of one moment. A game that writes its quests at one moment and its items at another can load a mix of two moments. The autosave blueprint behind this game warns of exactly that: a door already open while its key is still in the pocket.
Wait for the wasp. Now and then a wasp flies in at the window, and while it is in the room no save starts. The wasp stands for the moments in your game that a load cannot start from: a fight, a cutscene, a line half said. Now pour, and walk out of the door while the wasp is in the room. The save starts at once, because leaving may be the last chance.
So a save can still land in the middle of something, and that is why it holds facts and not the scene. When such a save is loaded, the game does not try to rebuild the half-said line. It starts the scene again from its beginning, with the facts as they were. A scene that hands something over asks a fact first, such as "the sword is given", so that it never hands it over twice.
Write the list for your own game. Next to every line of your story's facts, write where today's save holds it. A line with nothing next to it is something a player loses on the next load.
What goes wrong
Ask an AI to "add saving", and it saves what it can see in the code at that moment, such as where the player stands, their health and what they carry. Or it saves the scene, and on load plays that scene again. Both look right when you try them once: you stand in the right room, or in the right scene.
But the scene by the river asks whether the player spared the thief two scenes before, and the save does not know. The game answers with what a new game starts with: the thief was never spared. He is an enemy again, and nothing on the screen says why. That is the shortcut of this lesson: a save that keeps where the player stands and forgets what they did.
The gap opens again as the story grows. A new fact goes into the facts file and into the scenes, but not into the save, and nothing breaks on the day it is added. And a save from last week has no line for a fact you added today. If nobody decided what an old save gets, the code picks something by accident, or the load fails.
You notice all of these by comparing two lists, not by playing: the facts your story has, from its file, and the facts your save holds. A test that compares them, and names every fact missing from the save, fails on the day the gap is made, not on the day a player finds it.
Tell your AI
I want my game's save to keep the story, not only where the player stands. My story's facts are in [the file with your facts, for example story-facts.md].
Before you change any code, list everything a load must give back: every fact in that file, every quest with its state and step, every number a character keeps about the player, every item a later scene needs, and the place last. Next to each, write where the game sets it and where today's save holds it, or "not saved". Then list what stays out because the game can work it out from the facts, such as the scene on screen. Show me both lists and wait for my yes.
Then make the save one copy of all of it, taken at one moment, with a version number. A save loaded in the middle of a scene starts that scene from its beginning, and a scene that hands something over checks a fact first.
Write these tests, run them and show me their output:
- For each line of that first list: set it, save, load into a fresh game, check it came back.
- Save in the middle of [a quest of mine] at its second step, load, and finish the quest.
- Save in the middle of a scene that hands something over, load, and check the player has it once.
- Compare the facts file with the save, and fail with the fact's name when the save lacks one.
- Keep one save from today in a folder of old saves. After every change, load each and print what it gives back. When a fact is new, ask me what an old save gets for it.
Do not tell me saving works. Show me the output.
Try it
- In the game above, lock the chest with the down button, pour and stop. The bee bounces off, and the chest keeps its old number however often it tries. That old number is what a load would give back, so a failed save must never count as one.
- Pour, and walk out while the wasp is in the room. The save starts in a moment the game would never have chosen. Think of the same moment in your game, in the middle of a scene: what does your load do with it?
- In your own game, play to the middle of a quest, save, close the game completely and load. Is the quest at the same step, and does the last thing a character gave you come a second time? Keep that save, and load it again after your next change to the story.
Read up
Where to go deeper: the pages of ours this lesson builds on, and what others have written about its point.
How to Make Save Games That Keep the Story
A model checker walking saving and loading at every point of a small story, the exact path on which a fact is lost, and a proof that loading what was just saved gives back every fact.
The autosave of the game above as a whole blueprint: when a save starts and when it waits, why a failed save never counts, and the tested code your AI can build from.
Autosave Is On, but a Crash Loses More Than It Should
A bug our checker found in that same autosave: changes made while a save was being written waited too long, and what a crash can really cost once the save's own time is counted.
Saving the Day: Save Systems in Games
A designer's case that a player should be able to stop at any time without losing the progress that matters, with saves that keep that progress and not the exact place in a level.
One engine's own guide to a save: first choose what to keep between sessions, write each thing as one line of data, and clear the old state before loading so nothing comes back twice.
Check yourself: three questions
Each answer is checked and explained at once. The questions are part of the quiz, so they count for your Game Coder IQ like any other.
In the workshop game of this lesson, the number over the chest is lower than the number at the top left, and no bee is flying. The game crashes now. What does a load give back?
Next lesson When Your AI Forgets the Story: Keep the Facts in a File
How useful was this page?
Nobody has rated this page yet.