wyOOtdocs

Worked examples

A turn-based fight

Weapons, a potion, and creatures with health and attack.

On this page
Already know this?How it is built

A fight is only numbers. You have health and an attack. Each creature has health and an attack. Every turn both sides hit, and a fork decides who is still standing. This example has two weapons, one health potion and two paths, so you can see the whole pattern in a small story.

Try it#

Try it

The hill

You climb a hill to a cave. Inside, a magical dog is locked in a cage. Its fur glows softly. Two weapons lean against the wall by the entrance, and you can only carry one. The sword is light. It hits for 3, and you keep all 10 of your health. The war hammer is heavy. It hits for 5, but it tires you, so you only have 8 health.
  • health10
  • attack3
  • potions1
  • ogre_health9
  • goblin_health3
  • wolf_health6
  • ogre_attack4
  • goblin_attack3
  • wolf_attack3
Pick a weapon and a path. Try the hammer at the front gate without drinking the potion, then try again.

The rules#

Everything the reader needs to decide is written in the scenes, and here it is in one place.

HealthHits for
You, with the sword103
You, with the war hammer85
Ogre (front gate)94
Goblin (back tunnel)33
Wolf (back tunnel)63

You also have one health potion, which gives you 5 health. Drinking it does not cost you a turn.

The front gate is one hard fight. The back tunnel is a fight against the goblin and the wolf at the same time, so you take 6 damage every turn until one of them falls. You need the potion on both paths. In the tunnel you also have to pick who to attack first: kill the goblin first and, with the potion, you win. Kill the wolf first and you lose, even with the potion.

The map#

weapongatetunnelturn backattackkeep goingattack onekeep goingwolf deadgoblin deadThe hillTwo ways inThe ogreWho is standing?Goblin and wolfWho is standing?Only the goblinOnly the wolfThe cageThe dog is freeDefeatedTurned back
Every fight is a fight scene, an Attack choice and a fork. The tunnel has two creatures at once, and the fork sends you to a one-on-one fight with whichever is left. Every fork can also send you to 'Defeated', but only one of those arrows is drawn to keep the map readable.

How it is built#

The values#

Add these number values.

  • health, starting at 10.
  • attack, starting at 3.
  • potions, starting at 1.
  • Two values per creature, one for its health and one for how hard it hits: ogre_health at 9 and ogre_attack at 4, goblin_health at 3 and goblin_attack at 3, wolf_health at 6 and wolf_attack at 3.

Keeping the creatures' stats in values means a creature's numbers live in one place. Change wolf_attack once and every fight it appears in changes with it. The scene text is plain writing, so update it by hand.

Choosing a weapon#

The hill has two choices. Each has two Set to effects.

  • "Take the sword" sets attack to 3 and health to 10.
  • "Take the war hammer" sets attack to 5 and health to 8.

The scene text explains the trade: the hammer hits harder but tires you. The reader chooses knowing both numbers.

A fight scene#

Each creature has a scene with two choices. The scene text prints the numbers with Insert a value…: your health, the creature's health and your potions. The reader always sees the state of the fight before they act.

Attack the ogre has two effects.

  1. Subtract attack from ogre_health. Pick the value attack instead of typing a number, so the sword and the hammer both work from one choice.
  2. Subtract ogre_attack from health. The ogre hits back in the same turn.

It leads to the fork.

Drink the health potion has the check potions is at least 1, so it disappears when the potion is gone. Its effects are Add 5 to health and Subtract 1 from potions. It leads back to the same fight scene, so the reader can still attack.

The fork that decides#

Add a fork called "Who is still standing?" with three rules, in this order.

  1. If health is at most 0, send to "Defeated".
  2. If ogre_health is at most 0, send to "The cage".
  3. Otherwise, send back to "The ogre".

Order matters. If you and the ogre both reach 0 in the same turn, rule 1 comes first and you lose. Put the rules the other way round and a tie becomes a win.

Two creatures at once#

The tunnel is the same idea with one change: both creatures are in one fight scene, so both hit you every turn.

  • Every attack choice has two Subtract effects on health, goblin_attack and wolf_attack, because both creatures hit you.
  • The scene has one Attack choice per creature: "Attack the goblin" subtracts attack from goblin_health, and "Attack the wolf" subtracts it from wolf_health. The reader picks who to hit each turn.
  • The fork has three rules and an Otherwise, in this order. If health is at most 0, send to "Defeated". If goblin_health is at most 0, send to the wolf's one-on-one scene. If wolf_health is at most 0, send to the goblin's one-on-one scene. Otherwise, send back to the tunnel.

Once one creature is down, the reader lands in a smaller fight scene with only the other one, built exactly like the ogre's: it costs only that creature's attack per turn.

Why the order matters: the goblin dies in one hit and the wolf takes two. Killing the goblin first removes its attack from every turn after that. Killing the wolf first leaves you taking both attacks for an extra turn. The numbers are chosen so the second order costs one hit too many, and no choice of weapon or potion timing fixes it.

To add a creature of your own, copy a one-on-one fight scene and its fork, add the creature's two values, and change the scene text.

Why it works#

  • There is one rule for a fight and it is the same everywhere. The reader learns it once.
  • The numbers are printed in the scene, so nothing is hidden. The reader can plan: "the hammer needs the potion here".
  • Choices matter without any randomness. The result follows from the weapon, the path and when the reader drinks the potion, so a loss feels earned.
  • Order is a real decision. In the tunnel the reader has to work out who is the bigger threat, and the story shows them every number they need.
  • Two ways of playing are both possible. The hammer hits harder but has less health, and the sword is steadier.

Things to try#

  • Add a shield. A third weapon choice can set attack to 2 and health to 14.
  • Make the ogre hit harder or the potion heal more, and replay to see how the balance moves.
  • Make the fight less predictable by rolling for damage. See Rolling dice.
  • Add a secret ending for winning at the gate with the hammer, using a check on the story's choices. See Story history.

Make your own copy#

Want to take it apart? Copy this story into your Studio and change it however you like.

Next#

The last example puts all of these together. Read A full story, annotated.