Game design with Twine

blog/game-development/twine/

How I make my games in Twine, and what I have learnt along the way

I build interactive games that turn digital forensics and incident response into stories people want to play. Every one of them is made in Twine. This post is about how I work, the lessons I learnt the hard way, and the resource I put together so that you can build your own.

Why Twine

Twine is a free, open-source tool for writing interactive stories. A story is a set of passages joined by links: type [[Open the cellar door]] and Twine creates the next passage and draws the arrow on the story map. When the story needs more, story formats add variables, conditions, sound, CSS and JavaScript, and when it is finished, Twine publishes the whole game as one HTML file that runs in any browser.

That combination is why I keep coming back to it. Anyone can start with nothing but words and links, and the same tool still has room for dice rolls, timers and puzzles when a game needs them. For teaching, it means a game can be played in a classroom, at an outreach event or at home, with nothing to install.

How I make a game

  1. Pick the incident. A hacked list, a missing person, a compromised server. The incident decides which skills the player practises.
  2. Choose the skills. Decoding with CyberChef, reading logs, OSINT, carving hidden files. Each skill becomes a puzzle.
  3. Create the evidence. Log extracts, encoded messages, images with something hidden inside them.
  4. Map the passages. The main route, the branches, the dead ends, and a way for every route to reach an ending.
  5. Add the game layer. Variables, music, a look that fits the story, and a little luck.
  6. Playtest, fix, repeat. Every path, every ending, and at least one player who is not me.

What I have learnt

1

Start with the incident, not the code

My best games began as an investigation on paper. I decide what happened, what evidence would exist, and which skills a player needs to uncover it. Only then do I open Twine. The story map becomes the investigation plan.

2

Choose your story format before you write

Twine has several story formats, and each has its own code. Harlowe is the friendliest to start with; SugarCube is closer to JavaScript and better for bigger games, which is why I use it. Switching format halfway through breaks every macro you have written, so choose first.

3

Set every variable in one place

In SugarCube, the passage called StoryInit runs once before the game starts. I give every variable its starting value there, so nothing in the story ever reads a variable that does not exist, and I can see the whole game state at a glance.

:: StoryInit
<<set $playerName to "">>
<<set $health to 3>>
<<set $hasKey to false>>
<<set $cluesFound to 0>>
4

Use real true and false

This one is easy to miss. The word "false" in quotes is text, and text that is not empty counts as true. In one of my games, a location that should have stayed locked was open for every player.

<<set $hasKey to "false">>   /* text: this behaves like TRUE */
<<set $hasKey to false>>     /* a real boolean: this is what you want */
5

Spell every variable the same way

Variable names are case-sensitive. I once had an ending that checked $roomVisited while the rest of the game set $roomvisited, so nobody could ever reach it. Pick one style and keep a list of your variables in StoryInit.

6

Use Twine links, not web links

An ordinary HTML link such as <a href="Kitchen"> tries to open a web page called Kitchen. Inside a story, always use Twine’s own links so they go to the passage.

[[Go back to the kitchen->Kitchen]]
<<link "Try again" "Kitchen">><</link>>
7

Make answer checks forgiving

Players type spaces, capital letters and extra words. Trimming and lower-casing the answer before checking it removes most of the frustration without making the puzzle easier.

<<if String($answer).trim().toLowerCase() === "open sesame">>
  Correct! [[Open the door->Inside]]
<<else>>
  Not quite. [[Try again->The Door]]
<</if>>
8

Test every path to every ending

Branching stories hide dead ends. I have had a passage with no link out at all, and a whole route that could never reach the ending. I now play every branch, and I watch someone else play, because they always find the route I forgot.

9

Host your own evidence

Investigation puzzles that rely on a live social media post or someone else’s account stop working when that post or account disappears. Evidence I create and host myself, such as log extracts, encoded messages and images with hidden files, keeps working year after year.

10

Keep the sound gentle

Music adds atmosphere, but tracks that pile on top of each other are overwhelming. Play one track at a time, start quietly, and let players turn it down. Browsers also block sound until the player has clicked something, so never rely on music on the very first passage.

Setting.addRange("volume", {
  label   : "Sound volume",
  min     : 0, max : 100, step : 5, default : 30,
  onInit  : function () { SimpleAudio.volume(settings.volume / 100); },
  onChange: function () { SimpleAudio.volume(settings.volume / 100); }
});
11

Let CSS do the decorating

Images hosted on other sites break. Much of the look of my games is now drawn in the Story Stylesheet instead: backgrounds, borders, textures and simple decorations. CSS cannot go missing.

.passage {
  background: #f5f7fa;
  border-top: 6px solid #c8102e;
  border-radius: 10px;
  padding: 2em;
}
12

A little luck turns a story into a game

Borrowing from Dungeons and Dragons made my games far more fun. Players pick a character with strengths and weaknesses and roll a d20 at tense moments, and earlier choices can tip the odds. Even a simple random roll changes how a story feels.

<<set _roll to random(1, 20)>>
You rolled _roll.
<<if _roll >= 12>>The lock clicks open.<<else>>The pick snaps.<</if>>
13

Keep a plain-text copy of every game

Twine can export a story as Twee, a plain-text file with every passage, script and stylesheet inside. I keep one for each game as a backup and to compare versions. When I upload the published HTML to my server, I use Binary mode so nothing gets changed on the way.

My Twine Field Guide

Everything I have learnt, collected in one place. The Twine Field Guide is an interactive resource I made for my students: a horror edition that takes you from an empty story map to a published game. Every code sample switches between Harlowe 3 and SugarCube 2, so it works whichever format you choose.

Further reading

If you teach, run a club or just love a good mystery, open the cookbook and build one small story. Start with two passages and a clue, and see where it takes you.