Sub topic 6
Covering states and edge cases
This chapter assumes you can already write a spec with a design intent and numbered rules, as covered in the earlier chapters. It also assumes you know your team's basic roles: design, engineering, art, and QA. The goal here is to make the spec say what happens when the feature is not in its ordinary, happy-path condition.
Why rules alone are not enough
A rule such as "Pressing Dash starts a dash" describes one moment. It says nothing about what the player was doing just before, or what else is happening at the same time. Engineers must still decide what happens if the player is stunned, in the air, or already dashing. If the spec is silent, each engineer guesses, and the guesses differ.
Two ideas fill that gap:
- A state is a named condition the feature or the player can be in, such as Idle, Dashing, or Cooldown. Each state allows some actions and blocks others.
- An edge case is a situation at the boundary of the normal rules. It is rare, or it combines two systems, and the rules do not obviously cover it.
Most gameplay bugs come from states and edge cases that nobody wrote down.
Step 1: List the states
Start by naming every state the feature can be in. For each one, give it a short name and a one-line description. Use names that engineering and QA will also use, so that a bug report and the code say the same thing.
For the dash feature from the earlier chapters, the states might be:
| State | Description |
|---|---|
| Ready | The player may start a dash. |
| Dashing | A dash is in progress and lasts for the dash duration. |
| Cooldown | The dash has ended and cannot start again yet. |
| Disabled | An outside effect, such as a cutscene or a stun, blocks dashing. |
Check that the states are mutually exclusive. The feature should be in exactly one state at a time. If you find yourself saying "Dashing and also Cooldown," you probably have two separate state machines, for example one for the dash and one for the player's health, and you should list them separately.
Step 2: Describe transitions
A transition is a move from one state to another, caused by a trigger. Write each transition as: from state, trigger, optional condition, to state. A diagram makes the whole set easy to review at once.
The diagram shows the common mistake clearly. The dash spec said that damage cancels a dash, but it did not say what state follows. The diagram forces an answer: here, a cancelled dash still goes to Cooldown. A designer might disagree and want it to return to Ready, which is exactly the kind of decision you want made during review rather than during playtesting.
Write the same transitions as a table when you need exact wording for engineers:
| From | Trigger | Condition | To |
|---|---|---|---|
| Ready | Dash pressed | Air dashes remaining, if airborne | Dashing |
| Dashing | Duration ends | None | Cooldown |
| Dashing | Damage taken | None | Cooldown |
| Cooldown | Timer ends | None | Ready |
Step 3: Check every state against every trigger
The most reliable way to find missing behavior is to build a grid. Put states in the rows and triggers in the columns. Every cell must contain an outcome, even if the outcome is "ignored."
| State | Dash pressed | Damage taken | Wall hit | Cutscene starts |
|---|---|---|---|---|
| Ready | Start dash | No change | No change | Go to Disabled |
| Dashing | Ignored | Cancel, go to Cooldown | End dash, go to Cooldown | Cancel, go to Disabled |
| Cooldown | Ignored | No change | No change | Go to Disabled |
| Disabled | Ignored | No change | No change | No change |
Empty cells are the finding. If you cannot fill a cell, you have found a question. Move it to the Open questions section of the spec with an owner, so it does not get lost.
Step 4: Hunt for edge cases
Edge cases rarely appear by thinking "what else could go wrong?" in general. Use specific prompts instead.
- Boundaries. What happens at zero, at the maximum, or exactly at a threshold? If the cooldown is 0.8 seconds, can the player dash at exactly 0.8?
- Simultaneous events. What if two triggers arrive in the same frame, such as pressing Dash on the frame the player takes damage? State which one wins.
- Interruptions. What if the player pauses, dies, changes scene, or loses connection mid-action?
- Combinations with other features. What if the player dashes while carrying an object, while on a moving platform, or while another effect changes their speed?
- Input timing. What if the player presses Dash a few frames before the cooldown ends? Decide whether the input is buffered or dropped.
- Resources and limits. What if the feature runs out of something, such as air dashes, or the world has no room, such as a wall directly in front of the player?
- Save and load. What state should the feature be in when the game is loaded mid-dash?
You will not cover every possibility. Rank the cases by how likely they are and how bad the result is. A player dashing into a wall is common and must be specified. A dash on the exact frame of a level transition may only need a line saying "behavior is the same as a cutscene start."
Step 5: Write each edge case so it can be tested
An edge case entry should name the situation and the required result, in one or two lines. Avoid vague words like "handle gracefully."
## Edge cases
- Dashing into a wall ends the dash immediately and starts the cooldown.
- If Dash is pressed and damage is taken in the same frame, damage is applied first, so no dash starts.
- If Dash is pressed up to 0.1 seconds before the cooldown ends, the dash starts as soon as the cooldown ends (input buffer).
- If the game is saved during a dash, loading restores the player to Ready with no cooldown.
- If the player has no air dashes left, pressing Dash in the air does nothing and plays no sound.Notice that the buffer value of 0.1 seconds appears in the text. In a full spec you would move it to the tuning file, as shown later in the course, and refer to it by name, for example dash_input_buffer. The rule then stays fixed while the number can change.
Each of these entries converts directly into an acceptance scenario. The wall edge case, for example, becomes:
Feature: Dash edge cases
Scenario: Dash into a wall
Given the player is dashing and a wall is directly ahead
When the player touches the wall
Then the dash ends immediately
And the cooldown startsCommon mistakes
- Describing only the happy path. The spec reads well but leaves engineers to invent the rest.
- Hiding states in prose. If a state matters, give it a name and list it. Do not scatter it across paragraphs.
- Unstated priority. When two things happen at once, someone must win. Write down which.
- Listing edge cases with no outcome. "Dash while carrying an object" is a question, not an edge case, until it has a required result.
- Trying to cover everything. An exhaustive list nobody reads is worse than a short list of high-risk cases.
Exercise
Exercise
A spec says "A player can open the inventory with the Inventory button." You list the states Exploring, InCombat, InCutscene, and InventoryOpen. Name three triggers or situations that would produce empty cells in a state-by-trigger grid, and give the outcome you would write for one of them.
Show answer
Examples of empty cells: pressing Inventory during InCutscene, pressing Inventory during InCombat, and taking damage while InventoryOpen. A valid outcome for the first is "Ignored; the inventory does not open during a cutscene." Another valid answer is that the game pauses combat while the inventory is open. Any specific, testable outcome is acceptable, as long as every cell has one and it is recorded in the spec or in Open questions.
Exercise
A dash may be pressed on the same frame the player takes damage. Write one edge case entry for this, then say what the acceptance scenario's Given, When, and Then would be.
Show answer
Entry: "If Dash is pressed and damage is taken in the same frame, damage is applied first and no dash starts." Scenario: Given the player is in Ready; When the player presses Dash and takes damage in the same frame; Then no dash starts and the player is still in Ready (or in whatever state the damage effect requires).