Multiple Game Endings That Follow From What the Player Did

The demo is playing itself. Press a key or a button to take over.
Endings are checked from the top and the first that fits wins: the star needs the flower and both bars at 6, the heart needs kindness at 6 and at least as much as boldness, the sword boldness at 6, and staying home always fits. At the bridge the ending is fixed; only a fall can still change it.
Try it: Fill both bars to 6 without the flower: the slot shows the heart, because a tie goes to kindness. Cross the bridge, then help the beetle behind it: the bars do not move. Drive off the big nest past the bridge and see the stings end your walk with the grey heart, locked ending or not.
←→ walk Space help a beetle X drive off a nest ↓ search the bush
An ending is not written at the end. It is worked out from what the player did, by a rule you can read, and it holds when every ending on the list can be reached and the player can tell why she got hers. This lesson takes the walk home above apart, fills in a small table of every way through, and then has your AI do the same for your own game.
Also in this lesson 4 things to read up on 3 questions to check yourself
The idea
The walk home above has five endings: a star, a heart, a sword, the hive for staying home, and a grey heart for a fall. None of them is picked by a last button. Each comes from facts the game kept on the way: the heart bar for kindness, which rises when she turns over a beetle that lies on its back, the sword bar for boldness, which rises when she drives off a wasp nest, and a mark for the flower hidden in the bush.
Three things make endings like these hold. The rule is written down: a list of endings in a fixed order, each with what it needs, checked from the top, and the first one that fits wins. Every ending on the list has at least one way through the game that leads to it. And the player can see what her ending rests on, while she plays and when it comes.
How it works
Play the walk above a few times, with a piece of paper beside it.
Write the facts down. Watch the top while you play. Each bar holds up to 10 and has a black line at 6. One beetle fills the heart bar halfway to the line, the second reaches it, and the two nests do the same for the sword bar. The flower appears in the small slot beside the bars once you search the bush. Those three things are all the endings are worked out from: not where she stands, and not which beetle came first.
Write the list in its order. The game checks from the top and takes the first one that fits:
- the star: the flower, and both bars at the line
- the heart: kindness at the line, and at least as high as boldness
- the sword: boldness at the line
- the hive: always, so that every walk ends somewhere
A fall beats the whole list. The stings of the big nest past the bridge give the grey heart, whatever the bars say.
Fill in a table of every way through. Before the bridge there are two beetles, two nests and one bush, and each can be done or left. Draw a table with kindness down the side (nothing, halfway, at the line) and boldness across the top, and write the ending in each box, once without the flower and once with it. Work each box out with the list, from the top. The star stands in one box only: every beetle, every nest and the flower. The hive fills the most boxes. And every ending on the list stands in at least one box. That last sentence is what "every ending can be reached" means: a way to each one, found by going through every way, not by playing twice.
Look for the box that surprises you. Both bars at the line without the flower give the heart, not the sword, because a tie goes to kindness. The rule is right and written down, but it is nowhere on the screen. A player who did as much of one as of the other cannot tell from the bars why she got the heart.
Make the reason visible. The game above does two things for this. The slot in the corner shows, in grey, the ending that fits right now, so she sees it change while she plays; at the bridge it takes its colour and a lock, because the ending is fixed there. And the row of slots at the top keeps every ending she has reached, across new games, with empty slots for the ones she has not. In your own game, add a third: at the end, one sentence that names what the ending rests on, taken from the facts, such as "you helped every beetle you met".
What goes wrong
The shortcut is three endings of which one comes out whatever the player does. Each ending is well written, and the AI played to one of them and saw it work. Nobody went through every way.
On the game above you can see two ways this happens. Move the heart above the star in the list, and the star can never come: a player with the flower and both bars at the line also fits the heart, and the heart is checked first. Every line of the list still reads right on its own. Or set the line a little higher than two deeds can fill. The blueprint guards against a line above the cap by counting it as the cap, but the bar can hold 10 and the meadow never gives that much. No bar reaches the line, and every walk home ends at the hive. Tried on the blueprint's own rule with the meadow's deeds, the first change leaves no box for the star, and the second leaves nothing but the hive.
You notice it when you play twice, get the same ending twice, and decide the others are rare. Counting after release does not settle it either: a count of which endings real players reached cannot tell a rare ending from one that no way leads to. Going through every way can. Ask your AI for one line per ending with how many ways lead there. A line with none is the bug.
Tell your AI
I want every ending of my game to follow from what the player did, to be reachable, and to be explained to her: [your game and its endings in one or two sentences].
Before you change anything:
1. List every fact the ending is worked out from: scores, marks, items, finished quests. For each, say what changes it, and the lowest and highest value it can really reach with the deeds the game offers, not with its cap.
2. Write the endings as a list in the order they are checked, each with what it needs, ending with one that always fits. Say what happens when two fit at once, and what a death or a loss does.
3. Write a test that goes through every combination of what the player can do before the ending is fixed, works out the ending for each with the game's own code, and prints one line per ending: how many ways lead there, and one example way. Run it and show me the output as it came. If an ending has no way, say so, and change no number until I choose.
4. For every ending, write one sentence the game shows at the end that names what it rests on, using only facts the game keeps.
5. Show me where, before the end, the player can see which ending her deeds point to. If there is no such place, suggest one.
Do not tell me the endings work. Show me the test's output.
Try it
- In the game above, help one beetle and drive off both nests: the slot shows the sword. Walk back and help the beetle you passed: it turns into the heart, because a tie goes to kindness. Then search the bush, and the star takes its place.
- Walk home doing nothing. In the next game, drive off the big nest past the bridge. The row at the top now holds the hive and the grey heart, and its empty slots tell you how many endings you have not seen.
- Write the endings of your own game as a list in order and fill in the table for your facts. An ending with no box can never be reached. An ending that fills nearly every box is the one your players will keep getting.
Read up
Where to go deeper: the pages of ours this lesson builds on, and what others have written about its point.
The walk of this lesson as a whole blueprint: the lock at the point of no return, deeds after it, a death after the lock, endings seen across new games, and the tested code.
How to Write a Game Ending Players Remember
What an ending says once it is reached: every promise answered on every path, one shared last scene that changes in small parts, and a checker asked backwards whether an ending can be reached.
After release: which endings real players reach and which choices nearly everybody makes the same way, and why those counts cannot tell a rare ending from an impossible one.
Two ways to make the end of a story answer the player's choices: several goals that pull against each other instead of one win or lose, and a late split into separate last chapters.
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.
Your game has three endings. Whatever you try, you get the same one, and your AI says the other two are simply rare. What settles whether they can be reached at all?
Next lesson What a Save Game Must Hold: Facts, Not Where You Stand
How useful was this page?
Nobody has rated this page yet.