Multiple Endings
Multiple endings let one story finish in different ways, decided by what the player did. Keep a few scores and marks, check a list of endings in fixed order and take the first that fits, end the list with one that always matches, and lock the ending early at a point of no return.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Multiple Endings" to my game.
What it should do: Different endings make a story worth playing twice. The player must feel that their deeds led to the end they got, and must never reach a finish that looks like a mistake: no ending, the wrong one because of a hidden rule, or one that changes after it was shown.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> playing
playing: Story goes on
locked: Ending locked in
ended: Story over
playing --> locked: point of no return
playing --> ended: finishes or hero dies
locked --> ended: finishes or hero dies
ended --> [*]
```
Use these starting values:
- tallyCap: 10 points
- highAt: 6 points
Watch out for these common mistakes:
- Two endings fit at once: Tell your AI: check the endings in a fixed order, rarest first, take the first that fits, and decide what a tie does. Here a tie goes to mercy.
- No ending fits: Tell your AI: end the list with an ending that always matches.
- The rare ending hides behind a common one: Tell your AI: put the most demanding ending at the top of the list, and test that its conditions really reach it.
- A threshold above the maximum: Tell your AI: count a threshold above the cap as the cap.
- Deeds after the point of no return: Tell your AI: decide the ending when the point of no return passes, save it, and ignore later scores and marks.
- Dying after the ending was chosen: Tell your AI: a death always ends the story at once with its own ending, even after the ending was locked in.
- A restart that forgets the endings: Tell your AI: keep the seen endings apart from the story state and carry them over on a restart.
Do not change anything else in the game. Do not claim anything without proof: model what it takes, and show me what your solution rests on and how I can see that it works. If you cannot show something, say you do not know. When you are done, tell me in plain words how to try it.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP
What it does
Different endings make a story worth playing twice. The player must feel that their deeds led to the end they got, and must never reach a finish that looks like a mistake: no ending, the wrong one because of a hidden rule, or one that changes after it was shown.
How it runs, as a diagram
Everything it can be in, and what moves it on. Your AI builds from exactly this.
How it runs, as a diagram
- Story goes on → Ending locked in: point of no return
- Story goes on → Story over: finishes or hero dies
- Ending locked in → Story over: finishes or hero dies
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| tallyCap | 10 points | The most a score can hold. Ten is a size a player can reason about, and it stops a long game from making one score so large that nothing else matters. |
| highAt | 6 points | The score at which a trait counts as strong. Six of ten means the player has to rely on a trait for most of the story, not just now and then. A value above the cap counts as the cap, or an ending could never be reached. |
What usually goes wrong
Two endings fit at once
A player with high scores in both traits matches several endings. If the order is not written down, the result depends on how the code happens to be arranged, and the player cannot tell why they got it.
Fix: Tell your AI: check the endings in a fixed order, rarest first, take the first that fits, and decide what a tie does. Here a tie goes to mercy.
No ending fits
A player who did a little of everything matches nothing, and the story ends with a blank screen or an error.
Fix: Tell your AI: end the list with an ending that always matches.
The rare ending hides behind a common one
If the common ending is checked first, a player who meets the rare one's conditions still gets the common one, and the rare ending can never be reached.
Fix: Tell your AI: put the most demanding ending at the top of the list, and test that its conditions really reach it.
A threshold above the maximum
If the score needed for an ending is higher than the score can ever be, that ending is locked forever, and nobody notices until a player asks.
Fix: Tell your AI: count a threshold above the cap as the cap.
Deeds after the point of no return
A player who locked in their fate in the final battle can still change scores in the epilogue, and the ending shown at the start of the last scene turns out different at the end.
Fix: Tell your AI: decide the ending when the point of no return passes, save it, and ignore later scores and marks.
Dying after the ending was chosen
If a death is treated like any other deed, a player who dies in the final scene gets a victory ending.
Fix: Tell your AI: a death always ends the story at once with its own ending, even after the ending was locked in.
A restart that forgets the endings
A new game that clears everything also clears the list of endings seen, so the player cannot see how many are left.
Fix: Tell your AI: keep the seen endings apart from the story state and carry them over on a restart.
How to check it works
- A score of 4 and a cap of 10. 9 is added, or 9 is taken away, in two separate tries: The score is 10 in the first try and 0 in the second, never above the cap and never below zero.
- Mercy 7, boldness 8 and the mark of a found secret. The story finishes: The secret ending is chosen, though the kind and the bold ending also fit.
- Mercy 5 and boldness 5, both under the line of 6. The story finishes: The quiet ending is chosen, and every pair of scores gets some ending.
- Mercy 8 and boldness 8. The story finishes: The kind ending is chosen; with mercy 6 and boldness 9 it is the bold one.
- Mercy 7 and boldness 7. The story finishes once with the mark and once without it: With the mark the secret ending, without it the kind one; with boldness 5 it is the kind one even with the mark.
- Mercy 7 and the point of no return passed. The player adds boldness, sets a mark and loses mercy: All three are ignored and the story finishes with the kind ending.
- High scores, the secret mark, or an ending that was locked in. The hero dies: The story ends with the fallen ending.
- A story that is over. Any deed, lock-in, finish or death comes in: All are ignored and the ending stays.
- A cap of 5 and a strong-trait line of 8. Both scores reach 5 and the mark is set: The secret ending is chosen.
- A player who has reached the kind ending. They restart and die in the next play: The seen list holds kind and fallen, and an ending reached twice is listed once.
- A score of 3. The change is not a number or the mark has no name: It is ignored and the score stays 3; the same mark twice is listed once.
- No point of no return has passed. The player earns mercy 7, loses 5 and then the story finishes: The ending follows the scores at the end: the quiet one.
Works well with
- Branching Choices: Every ending should be reachable by at least one path. Walk the story once for each ending before you ship. Let the choices set the scores and marks, and decide the ending at the end.
- Quest Log: An ending that depends on quests should read the finished ones, not the ones the player happened to see. Count finished quests into the scores in the same step.
- Achievements: The seen list is a good source for a reward such as seeing every ending. Unlock the ending's reward when the story finishes.
Common questions
how do i add multiple endings to my game
Paste this: Add multiple endings. Keep two scores from 0 to 10, mercy and boldness, and a mark for a found secret. At the end check the endings in this order and take the first that fits: secret (mark and both scores 6 or more), kind (mercy 6 or more and at least boldness), bold (boldness 6 or more), then a quiet ending that always fits. A death always gives its own ending. Remember which endings the player has seen across restarts.
how many endings should a game have
Three to five is a good start for a small game. Each one must be reachable on purpose, and each should feel earned. Many endings that differ by one line feel cheap.
should the ending be decided at the end or earlier
Both can work. Deciding at the end rewards the whole story. Locking it in at a point of no return makes one big choice count and lets the epilogue be written for that ending. Pick one for each story and save the result.
what if the player earns two endings at once
Write down which comes first and test it. The rarest or most demanding ending goes at the top, and a tie between two traits needs its own rule, or the result looks random.
Where it comes from
We could not find a reliable origin for this one yet.
What was checked
- 15 tests pass on the reference code.
- The state diagram was checked against the code, at the default values and at every listed low and high value.
Your AI gets the code
Tested example code comes through the Spielerando connection, so your AI can use it right away. How to connect it