Sub topic 5
Specifying a Verb: Preconditions, Costs, Outcomes
This chapter assumes you can read short Python snippets. It also assumes you know what a player verb is and how verbs form a core loop. Here you learn to write a verb down precisely enough that a designer, a programmer, and a tester all read it the same way.
Why write a verb down
"The player can throw things" is an idea. It leaves open how often the player can throw, what throwing costs, what the player must hold, and what happens when the object lands. Each open question gets answered by someone eventually, often by accident in code.
A verb specification answers those questions in one place. Written as data, it lets you compare verbs side by side and spot a verb that is cheaper, faster, or stronger than everything else in the set.
The four parts of a verb
Every verb spec needs four parts.
| Part | Question it answers | Example for `throw` |
|---|---|---|
| Precondition | When is the verb allowed? | The player holds an object and is off cooldown |
| Cost | What does the player spend? | 15 stamina |
| Constraint | How often can it be used? | 1.0 second cooldown |
| Outcome | What changes in the world? | The held object leaves the hand and flies forward |
Preconditions and constraints decide whether the verb runs. Costs and outcomes describe what happens when it does. The first two answer "can I?" and the last two answer "what do I get, and what does it take from me?"
Cooldowns are technically a precondition, because they gate use. They are listed separately here because designers tune them separately from state checks such as "is holding an object."
Verbs as data
Writing the verb set as data makes the whole set visible at once. The first part of the spec is a name, a resource cost, and a cooldown.
from dataclasses import dataclass
@dataclass(frozen=True)
class Verb:
name: str
stamina_cost: int
cooldown: float # seconds
VERBS = {
"move": Verb("move", 0, 0.0),
"jump": Verb("jump", 10, 0.2),
"grab": Verb("grab", 5, 0.5),
"throw": Verb("throw", 15, 1.0),
}frozen=True makes each verb immutable. Balance changes then happen by editing the table, not by code that mutates a verb at runtime. That keeps the table the single source of truth.
Notice that move costs nothing and has no cooldown. Free verbs are normal. They are the baseline that costly verbs are measured against.
Preconditions: the gate
A precondition is a test that must pass before the verb starts. The two most common are a cooldown check and a resource check.
def can_use(verb, stamina, now, last_used):
last = last_used.get(verb.name, float("-inf"))
off_cooldown = now - last >= verb.cooldown
return off_cooldown and stamina >= verb.stamina_costTwo details matter here.
- A verb that has never been used has no entry in
last_used. Defaulting to negative infinity means it is always off cooldown the first time. - The comparison uses
>=. A verb with a 1.0 second cooldown becomes usable at exactly 1.0 seconds, not after it. Choose one rule and keep it everywhere, or players will find inputs that sometimes work and sometimes do not.
Other preconditions are about state, not resources. Examples are "the player is standing on the ground" for jump, "the player holds nothing" for grab, and "a target is within reach." You can add these as extra checks in the same function. Keep every check a pure yes-or-no question about current state, so you can test each one on its own.
Costs and the moment of payment
A cost is something the player gives up to perform the verb. Stamina is common, but costs can also be ammunition, time, a risk of damage, or a position that leaves the player exposed.
The spec must say when the cost is paid. The usual choices are:
- At the start of the verb. This is simple and predictable.
- On success only. This feels fair if the verb can fail, but players can then spam failing attempts for free.
- Partly at the start and partly on completion. For example, a wind-up cost is paid at once and a refund is given if the action is cancelled.
Whichever you choose, apply it consistently across verbs in the set. A player forms expectations about "what happens when I press the button and it doesn't work," and mixed rules make the game feel unreliable.
Putting the gate and the payment together
Here is a complete runnable version. It checks the precondition, pays the cost, records the time, and reports a result.
from dataclasses import dataclass
@dataclass(frozen=True)
class Verb:
name: str
stamina_cost: int
cooldown: float # seconds
VERBS = {
"move": Verb("move", 0, 0.0),
"jump": Verb("jump", 10, 0.2),
"grab": Verb("grab", 5, 0.5),
"throw": Verb("throw", 15, 1.0),
}
def can_use(verb, stamina, now, last_used):
last = last_used.get(verb.name, float("-inf"))
off_cooldown = now - last >= verb.cooldown
return off_cooldown and stamina >= verb.stamina_cost
def try_use(verb_name, state, now):
verb = VERBS[verb_name]
if not can_use(verb, state["stamina"], now, state["last_used"]):
return "rejected"
state["stamina"] -= verb.stamina_cost
state["last_used"][verb.name] = now
return "performed"
state = {"stamina": 20, "last_used": {}}
print(try_use("jump", state, 0.0)) # performed (stamina 10)
print(try_use("jump", state, 0.1)) # rejected (cooldown)
print(try_use("jump", state, 0.3)) # performed (stamina 0)
print(try_use("jump", state, 1.0)) # rejected (no stamina)The state is only changed after the check passes. A rejected attempt must leave stamina and last_used untouched. If a rejection resets the cooldown, a player who mashes the button locks themselves out indefinitely.
Outcomes: what actually changes
An outcome is a list of changes to the game state. Write outcomes as state changes, not as feelings. "The crate flies forward and the player loses the object" can be tested. "Throwing feels powerful" cannot.
An outcome often depends on the target. The same grab picks up a crate and pulls a lever. A lookup table keeps this readable and exposes gaps.
INTERACTIONS = {
("grab", "crate"): "pick_up",
("throw", "crate"): "launch",
("jump", "crate"): "climb_on",
("grab", "lever"): "pull",
}
def resolve(verb_name, target):
return INTERACTIONS.get((verb_name, target), "no_effect")
print(resolve("grab", "crate")) # pick_up
print(resolve("grab", "lever")) # pull
print(resolve("throw", "lever")) # no_effectThe default "no_effect" is a deliberate design decision. Decide for each empty cell whether the verb should do nothing, fail with a message, or get a new entry. The next chapters build on this table.
Failure, feedback, and edge cases
A rejected verb must tell the player why. A single boolean from can_use cannot do that. In a real game, return a reason such as "cooldown" or "no_stamina", so the interface can show a cooldown ring or a flashing stamina bar. A verb that silently does nothing reads as a bug.
Watch for these cases when you write a spec:
- Cooldown start. Decide whether the cooldown begins when the verb starts or when its animation ends. Starting at the beginning allows tighter chaining. Starting at the end punishes long animations.
- Input buffering. If the player presses a verb 50 milliseconds before it becomes available, should the game remember the press? A short buffer window forgives timing without changing the rules.
- Simultaneous verbs. State whether two verbs can run at once, and which one wins if both are requested in the same frame.
- Cost larger than the maximum resource. A verb costing 120 stamina when the maximum is 100 can never be used. Check each cost against the cap.
- Time source. Compare times from one consistent clock. Mixing real time and paused game time breaks cooldowns during pauses.
Reading the spec as a balance tool
Once verbs are data, you can scan them for problems. In the table above, throw costs three times as much as grab and has twice the cooldown. That is a claim that throwing is heavier than grabbing. If playtests show players never throw, either the outcome is too weak for the price or the precondition (holding an object) is too hard to meet. The spec tells you which numbers to question before you change anything else.
Exercise
Write a spec for a dash verb: a precondition, a cost, a cooldown, and an outcome. Then say which of these four is most likely to be misread by a programmer who only receives the sentence "the player can dash."
Show answer
Example: precondition, the player is on the ground and a direction is held. Cost, 20 stamina. Cooldown, 1.5 seconds. Outcome, the player moves 4 units in the held direction over 0.2 seconds and cannot be hit while moving. The outcome is the most likely to be misread, because distance, duration, and invulnerability are all unstated in the single sentence. The precondition (grounded or airborne) is a close second.
Exercise
In try_use, suppose you moved the line state["last_used"][verb.name] = now above the if check. What would happen to a player who presses jump repeatedly while out of stamina, and why is that a design problem?
Show answer
Every rejected press would reset the jump cooldown. The player would stay locked out even after stamina recovered, as long as they kept pressing. This punishes failed attempts with extra lockout, which feels like a bug. A rejection must leave state unchanged.