Sub topic 4
Fail States: Setbacks the Player Can Recover From
This chapter assumes you know the core gameplay loop, you can read simple Python (conditionals, functions, classes), and you have played several game genres. It builds on the earlier chapters on win and lose conditions.
What a fail state is
A fail state is a moment when the player has made a mistake or been hurt, and the game responds with a cost but lets play continue. A lose state ends the run. A fail state does not.
The same event can be either one. Falling into a pit is a fail state if the game puts you back at a checkpoint with one less life. It becomes a lose state when the last life is gone. The event is identical, and the number of resources left decides its meaning.
| Term | What happens | Does play continue? | Example |
|---|---|---|---|
| Win state | The goal is met | No, the run ends in success | Collect all relics |
| Lose state | The run cannot go on | No, the run ends in defeat | Health reaches zero with no lives left |
| Fail state | The player pays a cost | Yes | Lose a life and return to a checkpoint |
Designers use fail states because a game with only win and lose states is brittle. Every mistake would end the session, and players would quit before they learned the rules. Fail states let the player make many small errors and learn from each one. They are the main way a game teaches.
Four ingredients of a fail state
Most fail states combine four parts. You can tune each one separately.
- Trigger. The event that counts as a failure: a death, a missed jump, a failed timer, a broken stealth cover.
- Cost. What the player loses: a life, time, progress, a resource, or only a few seconds of animation.
- Reset target. Where the player goes next: the exact spot of failure, a checkpoint, the start of the level, or the main menu.
- Escalation. What changes if failures pile up: a lose state, extra help, or a harsher penalty.
A weak fail state usually has one of these parts set badly. A trigger the player cannot see coming feels unfair. A cost that is too small makes the failure meaningless. A reset target that is far away makes the player repeat solved content. Missing escalation lets players fail forever without the game responding.
Fail states as a design tool
Fail states do three jobs.
- Teaching. A failure shows the player which rule they misjudged. A short, clear failure teaches faster than a long lecture.
- Tension. The player cares about avoiding failure only if it costs something. The cost creates the stakes that make success feel earned.
- Pacing. A reset point sets the rhythm of play. Frequent small resets give a fast, experimental rhythm. Rare large resets give a slow, careful one.
Compare two games. In a precision platformer, a death costs about two seconds and restarts you on the same screen. Players try a jump fifty times without anger. In a survival game that deletes your inventory on death, each attempt is expensive, so players act cautiously and avoid risk. Both designs work. They produce different players and different feelings.
Implementing a fail state
The code below is the lives-and-checkpoint pattern. It uses the Outcome enum from the previous chapter. The full example is included so you can run it.
from enum import Enum, auto
class Outcome(Enum):
PLAYING = auto()
WON = auto()
LOST = auto()
class Run:
def __init__(self, lives, checkpoint):
self.lives = lives
self.checkpoint = checkpoint
self.position = checkpoint
def on_player_death(self):
# A death is a fail state while lives remain and a lose state when they run out.
self.lives -= 1
if self.lives == 0:
return Outcome.LOST
self.position = self.checkpoint
return Outcome.PLAYING
run = Run(lives=3, checkpoint=(10, 4))
run.position = (42, 7)
print(run.on_player_death(), run.lives, run.position)
print(run.on_player_death(), run.lives, run.position)
print(run.on_player_death(), run.lives, run.position)The first two deaths print Outcome.PLAYING, the lives count falls to 2 and then 1, and the position returns to (10, 4). The third death prints Outcome.LOST. The function returns the outcome and changes state in the same call, so the caller does not need to know the rules.
The four ingredients map to the code directly:
- The trigger is the call to
on_player_death. - The cost is
self.lives -= 1. - The reset target is
self.checkpoint. - The escalation is the
lives == 0check.
A common bug in this pattern
The check self.lives == 0 works only if lives can never skip past zero. If another system subtracts two lives at once, lives can become -1 and the run never ends. Use <= 0 for any counter that something else might decrement by more than one. The same reasoning applies to the health check in the evaluate function from the earlier chapter, which uses health <= 0 for this reason.
The fail-state loop
A fail state sits inside a loop of attempt, failure, feedback, and retry. The diagram shows where the lose state branches off.
The speed of this loop matters more than most designers expect. If the time from failure to the next attempt is short, players tolerate many failures. If it is long, each failure feels like a punishment. The next chapters on retry cost and feedback return to this point.
Kinds of fail-state costs
Costs fall into a few groups. Games often mix them.
- Time cost. The player replays content or waits. Cheap to build, but it hurts when the replay is long.
- Resource cost. The player loses lives, ammo, currency, or items. This adds a strategic layer, since players now manage the resource.
- Progress cost. The player loses score, a streak, or a multiplier. It suits games where the run itself is the goal.
- Positional cost. The player is moved backward, for example to a checkpoint. Its weight depends on the distance.
- Opportunity cost. A route closes, a character is lost, or a story branch changes. The game goes on, but the player has given something up.
Opportunity cost is the most interesting group because it lets a fail state change the game instead of only delaying the player. A rescue mission that fails and loses an ally keeps the game going, but the story is different afterward. This is also the case where a fail state is easy to confuse with a lose state, so the game must make clear that the run continues.
Edge cases
Simultaneous failure and success
Suppose a player grabs the last relic on the same frame that a trap kills them. This is the precedence question from the earlier chapters, and it applies to fail states too. The order of your checks decides the result. Decide the rule on purpose, write it down, and test it. Many games favor the player here, since a death that cancels a visible success feels cheating.
Failure during a transition
A player may die during a cutscene, a loading screen, or a menu animation. If the death is processed while input is locked, the player can fail without any chance to react. Common fixes are to make the player invulnerable during transitions or to hold the failure until the transition finishes.
Repeated failure on the same challenge
If a player fails the same section many times, the cost model has stopped teaching and begun to frustrate. A common response is to escalate help, such as offering a skip, adding a checkpoint, or reducing enemy damage. The chapter on adaptive difficulty covers this in detail. For now, note that the fail-state design should track failures per challenge, since a global death count hides the one section that is broken.
from collections import Counter
class FailureTracker:
def __init__(self, help_threshold):
self.help_threshold = help_threshold
self.by_section = Counter()
def record(self, section):
self.by_section[section] += 1
def needs_help(self, section):
return self.by_section[section] >= self.help_threshold
tracker = FailureTracker(help_threshold=5)
for _ in range(5):
tracker.record("boss_room")
tracker.record("tutorial")
print(tracker.needs_help("boss_room"))
print(tracker.needs_help("tutorial"))This prints True and then False. Only the boss room crossed the threshold, so only that section triggers help.
Failure that cannot be recovered
A fail state is only recoverable if the player can still win. A soft lock is the worst version of this bug: the player has failed in a way that makes winning impossible, but the game does not say so. Examples include using a one-time key on the wrong door or running out of the only ammo that can damage a boss. The game looks like it is still playing, so it is in neither a fail state nor a lose state.
There are two ways to deal with it. Prevent it, by making required items impossible to lose or by always providing a fallback. Or detect it, by checking whether the win condition is still reachable and ending the run honestly if it is not.
Choosing between a fail state and a lose state
Use these questions when deciding how a given event should resolve.
- Can the player still reach the win condition afterward? If not, it is a lose state.
- Did the player have enough information to avoid it? If not, soften the cost or improve the warning before anything else.
- Is the cost proportional to the mistake? A small slip should not erase an hour of progress.
- Does the cost make the player act differently next time? If it does not change behavior, it adds friction and no tension.
- How fast can the player try again? Shorten the loop before you shrink the penalty.
The last question is often the most useful. Many designers lower penalties when the real problem is a slow retry. A harsh cost with a two-second retry can feel lighter than a mild cost with a thirty-second one.
Summary
- A fail state costs the player something and lets play continue. A lose state ends the run.
- The same event can be either, depending on the resources left.
- Break a fail state into trigger, cost, reset target, and escalation, and tune each part alone.
- Use threshold comparisons for counters, handle simultaneous events by an explicit rule, and track failures per challenge.
- Guard against soft locks, which look like fail states but are really lose states in disguise.
Exercise
A stealth game gives the player three lives. When the player is spotted, they lose a life and restart at the last checkpoint. A level designer adds a trap that removes two lives at once, and testers report that sometimes the player has "negative lives" and the game keeps going. Identify the bug in the Run.on_player_death pattern and write the corrected condition. Then name which of the four fail-state ingredients the fix touches.
Show answer
The bug is the exact comparison self.lives == 0. With a trap that removes two lives, a player with one life drops to -1 and skips past zero, so the lose branch never runs. The fix is if self.lives <= 0:. This touches the escalation ingredient, which is the rule that decides when accumulated failures become a lose state. The trigger, cost, and reset target are unchanged.
Exercise
A player uses a single-use key on the wrong door in an adventure game. The key was required to open the final gate, and no other key exists. The game continues normally. Is this a fail state or a lose state, and what should the designer do? Give one prevention approach and one detection approach.
Show answer
It is a lose state in disguise, called a soft lock, because the player can no longer reach the win condition even though the game keeps running. Prevention: make the key reusable, let the wrong door refuse it, or provide a second way to get the key. Detection: check whether the win condition is still reachable after key use, and if it is not, tell the player and end the run or offer a reload from the last checkpoint.