Lesson 15.1
Write an interaction contract
In this module · Module 15
6 min
English captions
Objective
Write an interaction contract with state, event, precondition, postcondition, feedback, ownership and off-nominal behavior, including a race.
Take into your capstone
Write the interaction contract for relay 1, including the cancel race.
Open the cheat sheet →
Descriptive transcript
What’s on screen, then what’s said, scene by scene.
On screen: Title card. Lesson 15.1: Write an interaction contract. Objective: Write the rules engineering and QA need, including what happens when things go wrong.
Module fifteen. The studio moment: the UI artist has every relay asset ready. Engineering opens the ticket and asks one question: what happens if Rin lets go while Kai is signalling? Nobody knows. A mockup shows what the relay looks like. A contract says how it behaves. In this lesson you'll write one.
On screen: ONE ROW OF THE CONTRACT. Table, Kai signals at relay 1. Columns: Field, Value. Rows: Current state, Ready | Event, Kai presses signal | Precondition, Server has Rin's power as confirmed | Postcondition, Relay is Online for both players | Player feedback, Light, chime, rumble, RELAY 1 ONLINE on both screens | Owner of truth, Server | Off-nominal, If not confirmed: Invalid, with the reason
Here's one row of the contract. Current state: ready. Event: Kai presses signal. Precondition: the server has Rin's power as confirmed. Postcondition: the relay is online, for both players. Player feedback: light, chime, rumble, and RELAY 1 ONLINE on both screens. Owner of truth: the server. And off-nominal: if the precondition isn't met, the relay goes to invalid, with the reason. That last line is the one most specs leave out, and it's the one engineering always asks about.
On screen: Lantern Relay gameplay mockup, labeled “THE RACE // CANCEL VS. SIGNAL”. Top-down greybox: Kai (the player) and teammate Rin, a power junction linked to relay 1, the beacon above, teammate status card top right. Then the relay turns green: power is in, Rin's card reads POWER READY, a prompt above the relay reads “SIGNAL READY” with the E key. Then the frame freezes, magenta brackets frame the relay. Then the relay is fully lit: online, a toast reads RELAY 1 ONLINE, a label reads SERVER ORDER: SIGNAL FIRST.
Now the race. The relay is ready. Kai presses signal. In the same frame, Rin lets go of the lever. Two events, one moment. Without a rule, Kai's screen might say online while Rin's says power stopped. The contract decides it: the server processes events in the order it receives them. If the signal arrives first, the relay is online, and Rin letting go after that doesn't matter. If the cancel arrives first, the signal is invalid, with the reason. Both screens show the same outcome.
On screen: WHAT A GOOD CONTRACT COVERS. Heading: Before you hand it over. List: Every state and every event (Including invalid, timeout, cancel, reconnect.); Who owns the truth (Server, client, or both, for each state.); Feedback for both players (What each screen shows, and when.); Races and timeouts (What happens when two things happen at once.)
Before you hand it over, check the contract covers every state and every event, including the exceptions from module three. It names who owns the truth for each state. It describes feedback for both players. And it resolves races and timeouts. If engineering can find a case your contract doesn't answer, so can a player.
On screen: WORKED EXAMPLE. Table, Three more rows of the relay contract. Columns: State, Event, Precondition, Result, Off-nominal. Rows: Waiting, Kai presses signal, Power not confirmed, Stay waiting, Show 'Wait for Rin' | Ready, 40 s pass, No signal, Timeout, Power drains; both told | Ready, Rin disconnects, Any, Paused, Hold state 60 s for rejoin
Here are three more rows, the ones that usually get forgotten. Waiting, and Kai presses signal before power is confirmed. The relay stays waiting, and the off-nominal response is clear: show 'wait for Rin'. Ready, and forty seconds pass with no signal. The relay times out. Power drains, and both players are told. And ready, when Rin disconnects. The relay pauses, and holds its state for sixty seconds so Rin can rejoin. Without this row, a dropped connection could leave Kai alone at a relay that can never come online.
On screen: IN THE TOOL. Greyscale wireframe, Annotating states on the frames. Shows: WAITING · ring pulses; READY · shape + label; ONLINE · beam; Entry: relay found. Exit: power confirmed (server).; Entry: power confirmed. Exit: signal, timeout, disconnect.; Entry: signal accepted. Exit: none. Both see the beam.. Then it becomes a styled mockup. Then it becomes a styled mockup. Then it becomes a styled mockup. Then it becomes a styled mockup. Notes: One frame per state (Named as in the contract); Entry and exit on each (Every way in and out); Who owns the truth (Server or client); Link to the contract row (One source of truth).
Here's how the contract shows up in the design file. One frame per state, named exactly as in the contract: waiting, ready, online. Same words everywhere, so nobody has to translate. Under each frame, the entry and exit. Waiting: entered when the relay is found, exited when the server confirms power. Ready has three exits: signal, timeout and disconnect. If a frame lists one exit, it's probably missing two. And online: entered when the signal is accepted by the server, with no exit. Each note links to its row in the contract, so when the contract changes, the frames point to the latest version.
On screen: COMMON MISTAKE. Comparison, A spec that only shows success: WHAT TEAMS DO: Draw the happy path (Waiting, ready, online; Looks complete; Engineers invent the rest) versus WHAT WORKS: Every exit for every state (Timeouts, races, disconnects; Decided by design; Tested by QA)
The most common handoff gap: the spec shows the happy path. Waiting, ready, online. It looks complete. Then engineering hits a timeout, a race, a disconnect, and has to invent the behaviour on a Friday afternoon. Those choices ship, and nobody on the design side ever saw them. List every exit for every state, including the unhappy ones. Decide them in design, where they're cheap to change, and write them in the contract. Then QA tests exactly those rows. The happy path is maybe a third of the work.
On screen: WHO OWNS THE TRUTH. Heading: Client prediction vs. server authority. List: Server decides (Whether the relay is really online); Client predicts (Instant feedback while it waits); Correction is designed (What players see if the server says no); Both players agree (Never two different relays)
Online games need one more decision per state: who owns the truth. The server decides whether the relay is really online. That's the only way both players see the same thing. But waiting for the server feels slow, so the client predicts: it shows the flash instantly, then waits for confirmation. That means the correction must be designed. If the server says no, what do players see? A gentle 'not quite, power dropped', not a flash that silently vanishes. The rule at the end: both players must always agree on what the relay is doing.
On screen: RACE CONDITIONS. Table, When two things happen at once. Columns: Race, Rule, Both players see. Rows: Signal and lever release, same frame, Server orders by arrival, One result, the same for both | Timeout and signal together, Signal wins if it arrived first, Online, or a clear timeout | Rejoin during a state change, Rejoiner gets the current state, No replay of old events
Races are where co-op bugs live, so write a rule for each one. The signal and the lever release in the same frame: the server orders them by arrival. Both players see one result, the same result. A timeout and a signal arrive together: the signal wins if it arrived first. Players see online, or a clear timeout message, never a flicker between the two. And a player rejoins during a state change: they get the current state, not a replay of old events. Three rules, three rows. Each one prevents a bug report that would otherwise say 'sometimes the relay is weird'.
On screen: BEYOND LANTERN RELAY. Heading: A contract for a trading screen. List: States (Offering, both ready, confirmed, cancelled); Precondition (Both players have the items); Race (One player changes the offer as the other confirms); Rule (Any change resets both 'ready' flags)
Trading between players needs the same contract. States: offering, both ready, confirmed, cancelled. Precondition: both players still have the items they offered. The classic race: one player changes the offer at the exact moment the other confirms. Without a rule, someone could confirm a trade they never saw. The rule: any change to the offer resets both ready flags, and both players must confirm again. One row in a contract, and an entire category of scams disappears. So before any handoff, read your contract one state at a time and ask three questions. How do you get in? Every way out, including failure? And who decides the truth? Any blank answer is a decision engineering will make for you, usually late, and usually without the player in mind.
On screen: PAUSE AND PREDICT. Question: Which line is missing from most relay specs? Options: A) The relay's colour; B) What happens when the precondition isn't met; C) The name of the asset file. After a pause, answer B is highlighted.
Which line is missing from most relay specs? The colour? What happens when the precondition isn't met? Or the asset name? The off-nominal behavior. Colours and file names get specified because they're visible in the mockup. Failure doesn't appear in a mockup until someone draws it.
On screen: Recap checklist: Specify behavior, not just appearance.; State, event, pre- and postcondition, feedback, owner.; Write the off-nominal line every time.; Resolve races with one owner of truth.. Capstone box: Write the interaction contract for relay 1, including the cancel race.
Let's recap. Specify behavior, not just appearance. Fill every field. Write the off-nominal line. And resolve races with one owner of truth. For your capstone, write the contract for relay one, race included. Next lesson, we review it with the people who'll build it.