/* Variables initialised here run before the story begins.
This is a good place to set all your starting values. */
<<set $carried to "">>
<<set $clues to 0>>
<<set $instantText to true>>
<<set $hasTicket to false>>
<<set $helped to false>><span id="nav-caption">[[Map]]</span>You are holding a guide that knows it is being read.
This is appropriate. You are about to make things that know they are being played.
This is a tutorial for Twine, using the SugarCube story format. It was made for Week 5 of the course. The techniques it describes are at work in the passages you are reading right now. In Twine, you can double-click any passage to see how it was made.
<span class="note">Playing this in a web browser? You can read the whole tutorial here, but to see how each passage was made, download the .twee file and import it into Twine. [[Setting up Twine|Getting Started]] explains how.</span>
[[Continue|Map]]<h2>What do you want to learn?</h2>
This guide covers twelve sections plus a Quick Reference. They build on each other, but you can also jump around and use it as a reference.
[[Before you start: Setting up Twine|Getting Started]] - getting Twine, keeping your work safe, importing this file, and the best how-to guides.
[[Section 1: Passages and Links|1 Basics]] - the fundamental building blocks. Start here if you have not used Twine before.
[[Section 2: Variables and State|2 Variables]] - storing information and making choices matter.
[[Section 3: Styling and Atmosphere|3 Styling]] - changing how your game looks and feels.
[[Section 4: Macros|4 Macros]] - revealing text, adding timing, building interactivity.
[[Section 5: Techniques from the Course Games|5 Games]] - specific CSS from Howling Dogs, With Those We Love Alive, and Quing's Quest VII.
[[Section 6: Mechanics Examples|6 Mechanics]] - <<timed>>, visible unavailability, and typewriter text, drawn from three additional games.
[[Section 7: Advanced Techniques|7 Advanced]] - persistent sidebar, audio, conditional CSS classes, and reusable widgets.
[[Section 8: Images and Packaging|8 Images]] - adding pictures and handing in a portable project.
[[Section 9: Testing and Debugging|9 Debugging]] - find a fault, inspect a variable and check both branches.
[[Section 10: Accessibility and Reader Control|10 Accessibility]] - keyboard access, readable text and a choice of reading pace.
[[Section 11: A Complete Mini-project|11 Mini-project]] - plan, build and playtest a short branching story.
[[Section 12: Saves, Restart and History|12 Saving]] - understand what happens to choices when you save or go back.
[[Quick Reference|Quick Reference]] - all the syntax on one page.
<span class="note">Sections 1 to 4 end with a working example you can play. Sections 5 to 7 give you annotated code and CSS to lift into your own game. Section 8 adds images, an example ZIP and a hand-in checklist. Sections 9 to 12 help you test a complete project and make it usable for other readers. Open any passage in Twine to see how it was made.</span><h2>Setting up Twine</h2>
''Get Twine.'' You can <a href="https://twinery.org/2" target="_blank" rel="noopener">use Twine in your web browser</a> with nothing to install, or <a href="https://twinery.org/" target="_blank" rel="noopener">download the app</a> for Windows, macOS or Linux. The app is safer for a project you will work on over several weeks. <a href="https://twinery.org/reference/en/getting-started/installing.html" target="_blank" rel="noopener">Installing Twine</a> compares the two.
''Keep your work safe.'' Browser Twine saves your stories inside the browser itself. If the browser's storage is cleared, or you use a shared or university computer, your work can disappear. Do not use browser Twine in Safari on a Mac. Whichever version you use, choose Library, then Archive, at the end of every session and keep the file somewhere backed up. See <a href="https://twinery.org/reference/en/story-library/exporting.html" target="_blank" rel="noopener">Archiving and Exporting Stories</a> and <a href="https://twinery.org/reference/en/troubleshooting/backups.html" target="_blank" rel="noopener">Backups</a>.
''Import this tutorial.'' Download the .twee file, then in Twine's story library choose Library, then Import, and pick the file. Open it and double-click any passage to see the code behind what you are reading. See <a href="https://twinery.org/reference/en/story-library/creating.html" target="_blank" rel="noopener">Creating, Copying and Importing Stories</a>.
''Use SugarCube.'' New stories may start in a different story format. Open your story, choose Story, then Details, and pick SugarCube from the story format menu. Everything in this tutorial is SugarCube code. See <a href="https://twinery.org/reference/en/editing-stories/changing-story-format.html" target="_blank" rel="noopener">Changing the Story Format</a>.
''Find the stylesheet.'' The CSS in Sections 3, 5 and 7 goes in Story, then Stylesheet, not in a passage. See <a href="https://twinery.org/reference/en/editing-stories/js-and-css.html" target="_blank" rel="noopener">Editing Story JavaScript and CSS</a>.
<h3>The best how-to guides</h3>
<ul class="howto-list">
<li><a href="https://twinery.org/reference/en/getting-started/basic-concepts.html" target="_blank" rel="noopener">Twine Reference: Basic Concepts</a> - passages, the story library and story formats, briefly.</li>
<li><a href="https://twinery.org/cookbook/questions/getting_started.html" target="_blank" rel="noopener">Twine Cookbook: How do I get started?</a> and <a href="https://twinery.org/cookbook/starting/twine2/firststory.html" target="_blank" rel="noopener">First Story</a> - a walk through making a first game.</li>
<li><a href="https://sfwa.org/2017/03/18/writers-guide-twine-part-one/" target="_blank" rel="noopener">Aidan Doyle, Writer's Guide to Twine</a> - on the module reading list. It dates from 2017, so some menus have moved.</li>
<li><a href="https://www.motoslave.net/sugarcube/2/docs/" target="_blank" rel="noopener">SugarCube documentation</a> - the full reference for every macro used here. Search it for the macro name, for example <a href="https://www.motoslave.net/sugarcube/2/docs/#macros-macro-timed" target="_blank" rel="noopener"><<timed>></a> or <a href="https://www.motoslave.net/sugarcube/2/docs/#macros-macro-linkappend" target="_blank" rel="noopener"><<linkappend>></a>.</li>
</ul>
<h3>Cookbook recipes for the course games</h3>
<ul class="howto-list">
<li><a href="https://twinery.org/cookbook/timedpassages/sugarcube/sugarcube_timedpassages.html" target="_blank" rel="noopener">Timed passages</a> - the forced navigation of Queers in Love at the End of the World.</li>
<li><a href="https://twinery.org/cookbook/cycling/sugarcube/sugarcube_cycling.html" target="_blank" rel="noopener">Cycling choices</a> - the purple links in With Those We Love Alive.</li>
<li><a href="https://twinery.org/cookbook/conditionalstatements/sugarcube/sugarcube_conditionalstatements.html" target="_blank" rel="noopener">Conditional statements</a> - the choices Depression Quest makes unavailable.</li>
<li><a href="https://twinery.org/cookbook/googlefonts/sugarcube/sugarcube_googlefonts.html" target="_blank" rel="noopener">Google Fonts</a> - fonts like the Open Sans of With Those We Love Alive or the Comic Neue of Quing's Quest VII.</li>
<li><a href="https://twinery.org/cookbook/typewriter/sugarcube/sugarcube_typewriter.html" target="_blank" rel="noopener">Typewriter effects</a>, <a href="https://twinery.org/cookbook/sidebar_left/sugarcube/sugarcube_sidebar_left.html" target="_blank" rel="noopener">the sidebar</a> and <a href="https://twinery.org/cookbook/audio/sugarcube/sugarcube_audio.html" target="_blank" rel="noopener">audio</a> - Sections 6 and 7.</li>
</ul>
<h3>Testing and sharing</h3>
<ul class="howto-list">
<li><a href="https://twinery.org/reference/en/publishing/testing.html" target="_blank" rel="noopener">Testing a Story</a> - Test mode shows your variables as you play.</li>
<li><a href="https://twinery.org/reference/en/publishing/publishing.html" target="_blank" rel="noopener">Publishing a Story</a> - turn your game into a single HTML file.</li>
<li><a href="https://twinery.org/cookbook/starting/twine2/publishing_on_itchio.html" target="_blank" rel="noopener">Publishing on itch.io</a> - put it online for others to play.</li>
<li><a href="https://twinery.org/reference/en/troubleshooting/lost-story.html" target="_blank" rel="noopener">If Twine Lost Your Story</a> and the <a href="https://intfiction.org/c/authoring/twine/46" target="_blank" rel="noopener">Twine forum at intfiction.org</a> - when something goes wrong.</li>
</ul>
<span class="note">These links are also collected on the <a href="https://drrosiegraham.com/teaching/twine/" target="_blank" rel="noopener">Twine resources page</a>, alongside the visual techniques guide.</span>
<div class="section-footer">[[Back to Map|Map]]   [[Start with Section 1|1 Basics]]</div><h2>Section 1: Passages and Links</h2>
A Twine game is made of passages. Each passage is a box in the editor. It has a name and it has content. The content is what the reader sees.
When you open Twine and create a new story, you start with one passage called ''Start''. You can rename it. Select a passage, then click "Start Story Here" in the toolbar to make it the opening passage.
Names matter. A passage called <code>the archive</code> is different from <code>The Archive</code>. Spelling and capitalisation must match exactly when you link to a passage.
You can put anything in a passage: text, HTML, or SugarCube macros.
[[How to make links|1 Links]]
<div class="section-footer">[[Back to Map|Map]]</div><h2>Links</h2>
A link moves the reader from one passage to another. There are three ways to write them.
<span class="label-code">Syntax 1 - the passage name is the link text</span>
<span class="code-box"><nowiki>[[Passage Name]]</nowiki></span>
This displays "Passage Name" as the clickable link and navigates to the passage with that name.
<span class="label-code">Syntax 2 - different display text and passage name (most common)</span>
<span class="code-box"><nowiki>[[what the reader sees|Passage Name]]</nowiki></span>
The text before the pipe (<code>|</code>) is what the reader clicks. The text after is the passage it goes to.
<span class="label-code">Syntax 3 - arrow notation (does the same as Syntax 2)</span>
<span class="code-box"><nowiki>[[what the reader sees->Passage Name]]</nowiki></span>
<span class="label-code">Example in use</span>
<span class="code-box"><nowiki>You are standing at the edge of the archive.
[[Go inside|Archive Interior]]
[[Turn back toward the water|Waterfront]]</nowiki></span>
This passage gives the reader two choices. Each link goes to a differently named passage.
Now try a working example. This is a three-passage story built only with links.
[[Play the example|1 Example Start]]
<div class="section-footer">[[Back to Map|Map]]   [[Next: Variables|2 Variables]]</div>''You are at the edge of the city. Night has arrived without announcing itself.''
The archive is ahead: a low building with lit windows. Behind you, the water.
[[Enter the archive|1 Example Archive]]
[[Walk toward the water|1 Example Water]]
<span class="note">Double-click this passage in Twine to see the link syntax.</span>The archive smells like paper and something warmer underneath. A person looks up from a desk. They do not seem surprised to see you.
"We were expecting someone," they say. They do not say who.
[[Ask what they mean|1 Example End A]]The water does not move the way water usually moves. You stand at the edge of it for a while.
Something is wrong with the light. You decide to stay anyway.
[[Stay until something changes|1 Example End B]]You sit down. You do not know why.
The person hands you a guide. "This will help," they say.
You look at the guide. It knows it is being read.
[[Back to Section 1|1 Links]]You stay until the light corrects itself.
It doesn't.
You decide this is fine.
[[Back to Section 1|1 Links]]<h2>Section 2: Variables and State</h2>
SugarCube keeps a history of the passages you visit. To record your own details, such as a possession or a choice that changes what happens later, use variables.
A variable stores a piece of information. In SugarCube, story variables begin with a <code>$</code> sign and keep their values between passages. Temporary variables begin with <code>_</code> and last for the current turn.
<span class="label-code">Storing a value with <<set>></span>
<span class="code-box"><nowiki><<set $name to "Fen">>
<<set $count to 0>>
<<set $hasKey to true>></nowiki></span>
We will start with three kinds of value:
- text (called a string, written in quotes)
- a number
- a boolean (true or false)
To display a variable's value in passage text, write its name:
<span class="code-box"><nowiki>Your name is $name.</nowiki></span>
<span class="label-result">Live example (this is actually running)</span>
<<set $exampleName to "Fen">>
<span class="demo-box">Your name is $exampleName.</span>
You can do arithmetic with numbers:
<span class="code-box"><nowiki><<set $count to $count + 1>>
<<set $count += 1>> <!-- both lines do the same thing --></nowiki></span>
There is also a special passage called <code>StoryInit</code>. Any <code><<set>></code> macros placed there run before the story begins, which is a clean way to give all your variables their starting values. Open the <code>StoryInit</code> passage in this file to see an example.
[[Making variables change the story|2 If]]
<div class="section-footer">[[Back to Map|Map]]</div><h2>Conditionals: <<if>></h2>
Once you have a variable, you can use it to show different content depending on its value.
<span class="code-box"><nowiki><<if $hasKey eq true>>
The door opens.
<<else>>
The door does not open.
<</if>></nowiki></span>
The <code>eq</code> means "equals." Common comparison operators:
<span class="code-box"><nowiki>eq equals
neq does not equal
gt greater than
gte greater than or equal to
lt less than
lte less than or equal to</nowiki></span>
You can add more branches with <code><<elseif>></code>:
<span class="code-box"><nowiki><<if $mood eq "calm">>
You feel steady.
<<elseif $mood eq "afraid">>
Your hands are not quite still.
<<else>>
You feel something, but have no word for it.
<</if>></nowiki></span>
Try a working example. You make a choice that is carried into the next passage.
[[Try the example|2 Example Choice]]
<div class="section-footer">[[Back to Map|Map]]   [[Next: Styling|3 Styling]]</div>Someone asks: what do you carry with you?
<<link "Something sharp" "2 Example Result">><<set $carried to "something sharp">><</link>>
<<link "Something soft" "2 Example Result">><<set $carried to "something soft">><</link>>
<<link "Nothing at all" "2 Example Result">><<set $carried to "nothing at all">><</link>>
<span class="note">Each link here uses <<link>> instead of [[ ]]. This lets it run a <<set>> macro before navigating. Open this passage in Twine to see how.</span>The next room is very quiet.
You walk in carrying $carried.
<<if $carried eq "something sharp">>
The quiet notices.
<<elseif $carried eq "something soft">>
The quiet softens further.
<<else>>
The quiet has nothing to work with.
<</if>>
<span class="note">The text above changed based on what you chose in the previous passage. Open both passages in Twine to see the variable being set and then used.</span>
[[Back to Section 2|2 If]]<h2>Section 3: Styling and Atmosphere</h2>
How your game looks is part of how it means. Porpentine's games are inseparable from their visual weight: the dark backgrounds, the pacing, the way text arrives and sits on the screen.
SugarCube gives you several layers of control.
''Layer 1: Text formatting shortcuts''
You can format text directly in passage content:
<span class="code-box"><nowiki>//italic//
''bold''
__underline__
==strikethrough==</nowiki></span>
<span class="label-result">In use</span>
<span class="demo-box">//This is italic.// ''This is bold.'' __This is underlined.__ ==This is struck through.==</span>
''Layer 2: HTML inline''
HTML works directly in passage text. You can use <code><span></code> tags to apply styles:
<span class="code-box"><nowiki><span style="color: #a08060;">This text is warm.</span>
<span style="opacity: 0.4;">This text is faded.</span></nowiki></span>
<span class="label-result">In use</span>
<span class="demo-box"><span style="color: #a08060;">This text is warm.</span> <span style="opacity: 0.4;">This text is faded.</span></span>
''Layer 3: CSS classes''
You can define a class in the story stylesheet (Story > Stylesheet) and apply it wherever you need it. This keeps things consistent across the whole game.
[[The story stylesheet|3 Stylesheet]]
<div class="section-footer">[[Back to Map|Map]]</div><h2>The Story Stylesheet</h2>
Open Story > Stylesheet in the Twine editor to edit the CSS for your whole game. Creating an ordinary passage named <code>StoryStylesheet</code> does not turn it into a stylesheet. In this tutorial's Twee source, the stylesheet is stored as <code>StoryStylesheet</code> with the <code>stylesheet</code> tag; Twine imports it into the stylesheet editor.
A basic stylesheet:
<span class="code-box"><nowiki>body {
background-color: #0a0a0a;
color: #d0c8c0;
font-family: Georgia, serif;
font-size: 18px;
line-height: 1.8;
}
#passages {
padding: 2em 3em;
}
a.link-internal {
color: #a0b0c8;
text-decoration: none;
}</nowiki></span>
Useful CSS properties for atmosphere:
<span class="code-box"><nowiki>background-color background of the page
color text colour (use hex codes: #rrggbb)
font-family typeface
font-size size (px or em)
line-height space between lines
letter-spacing space between characters
opacity transparency (0 to 1)</nowiki></span>
You can also define your own classes:
<span class="code-box"><nowiki>.dim-text {
color: #505050;
}
.warning {
color: #d08060;
font-style: italic;
}</nowiki></span>
Then in a passage: <code><span class="dim-text">something faded</span></code>
The story stylesheet in this tutorial already defines three atmosphere classes. See them in practice:
[[See the styling example|3 Example Atmosphere]]
<div class="section-footer">[[Back to Map|Map]]   [[Next: Macros|4 Macros]]</div><div class="atmos-base">
You are in a room that is trying to tell you something.
<span class="atmos-dim">The walls hold the shape of a conversation that ended badly.</span>
You sit with this for a moment.
<span class="atmos-warm">Everything here was someone's.</span>
<span class="atmos-dim">You do not know whose.</span>
[[Leave|3 Example Exit]]
</div>The previous passage used three CSS classes from the story stylesheet:
- <code>.atmos-base</code>: slightly brighter base text on the whole passage
- <code>.atmos-warm</code>: a warm italic for emphasis
- <code>.atmos-dim</code>: faded text that recedes from the reader
Open the previous passage in Twine to see the classes applied. Then choose Story > Stylesheet to find their definitions.
This is how atmosphere works. Not through elaborate effects, but through controlled weight and distance.
[[Back to Section 3|3 Stylesheet]]   [[Next: Macros|4 Macros]]<h2>Section 4: Macros</h2>
Macros are SugarCube's built-in tools for adding behaviour to passages. You have already used two: <code><<set>></code> and <code><<if>></code>. These are the interactive ones.
''<<linkappend>>: revealing text on demand''
The <code><<linkappend>></code> macro turns a phrase into a trigger. When the reader clicks it, the phrase stays in place and new content is appended right after it.
<span class="code-box"><nowiki><<linkappend "a phrase">>
Something appears here when the phrase is clicked.
<</linkappend>></nowiki></span>
<span class="label-result">Live example</span>
<span class="demo-box"><<linkappend "There is something behind the door.">> It is not what you expected. It never is.<</linkappend>></span>
<span class="note">The trigger text stays visible and the revealed text appears after it. Older SugarCube tutorials may use <<click>>. It was deprecated in earlier SugarCube 2 versions and removed in 2.37. Use <<linkappend>> for this reveal.</span>
''<<link>> with actions''
You already saw this in Section 2: <code><<link>></code> creates a clickable link that can also run macros before navigating.
<span class="code-box"><nowiki><<link "Take the key" "Next Passage">>
<<set $hasKey to true>>
<</link>></nowiki></span>
[[Timing and typewriter effects|4 Timed]]
<div class="section-footer">[[Back to Map|Map]]</div><h2>Timing: <<timed>> and <<type>></h2>
Two macros for controlling when text arrives.
''<<timed>>: delayed appearance''
<span class="code-box"><nowiki><<timed 2s>>
This appears after 2 seconds.
<</timed>></nowiki></span>
You can chain multiple moments with <code><<next>></code>:
<span class="code-box"><nowiki><<timed 1s>>
First.
<<next 1.5s>>
Then this.
<<next 2s>>
Then this.
<</timed>></nowiki></span>
''<<type>>: typewriter effect''
<span class="code-box"><nowiki><<type 40ms>>
This text appears letter by letter.
<</type>></nowiki></span>
The number is the delay between each character. Lower is faster. You can nest <code><<type>></code> inside <code><<timed>></code> to delay when typing begins.
<span class="note">Use these effects deliberately. Porpentine's timed reveals create dread or tenderness because they are earned by the surrounding text. Used carelessly, they just make the reader wait.</span>
[[See a combined macro example|4 Example Macros]]
<div class="section-footer">[[Back to Map|Map]]   [[Quick Reference|Quick Reference]]</div>You enter a passage that uses linkappend, timed, and type together.
<<linkappend "Look at the light.">>
<<timed 0.3s>>
The light is wrong.
<<next 1.8s>>
You knew this already.
<<next 1.5s>>
You knew it when you arrived.
<<next 1.5s>>
<<type 45ms>>You have known it for some time.<</type>>
<</timed>>
<</linkappend>>
<span class="note">This passage uses <<linkappend>> to trigger, <<timed>> to pace the reveal, and <<type>> for the final line. They are nested inside each other. Open the passage in Twine to see how they stack.</span>
[[Back to Section 4|4 Timed]]   [[Quick Reference|Quick Reference]]<h2>Quick Reference</h2>
''Links''
<span class="code-box"><nowiki>[[Passage Name]]
[[Link Text|Passage Name]]
[[Link Text->Passage Name]]</nowiki></span>
''Setting and displaying variables''
<span class="code-box"><nowiki><<set $text to "a string">>
<<set $number to 0>>
<<set $flag to true>>
<<set $number += 1>>
Display in passage text: $variable</nowiki></span>
''Conditionals''
<span class="code-box"><nowiki><<if $variable eq "value">>
...
<<elseif $variable eq "other">>
...
<<else>>
...
<</if>>
Operators: eq neq gt gte lt lte</nowiki></span>
''Text formatting shortcuts''
<span class="code-box"><nowiki>//italic// ''bold''
__underline__ ==strikethrough==</nowiki></span>
''Macros''
<span class="code-box"><nowiki><<linkappend "trigger text">>
revealed content
<</linkappend>>
<<timed 2s>>
content
<<next 1.5s>>
more content
<</timed>>
<<type 40ms>>
typewriter text
<</type>>
<<link "text" "Passage Name">>
<<set $variable to value>>
<</link>></nowiki></span>
''Images and packaging''
<span class="code-box"><nowiki><img src="images/room.svg" alt="An empty room with a blue window.">
[img[An empty room with a blue window.|images/room.svg]]</nowiki></span>
Export index.html beside images/, zip the files together, then extract and test the ZIP. [[Full image and packaging instructions|8 Images]].
''Special passages you create''
<span class="code-box"><nowiki>StoryInit runs before the story starts; initialise variables here
StoryCaption appears in the sidebar on every passage
PassageHeader appears at the top of every passage
PassageFooter appears at the bottom of every passage</nowiki></span>
<span class="note">The story title and the stylesheet are not passages you create. You set the title when you name the story, and you edit the stylesheet through Twine's own menus (see Section 3).</span>
<div class="section-footer">[[Back to Map|Map]]   [[Setting up and how-to guides|Getting Started]]   [[Techniques from the Course Games|5 Games]]</div><h2>Section 5: Techniques from the Course Games</h2>
The games you played for this week all have distinctive visual approaches. This section adapts visual techniques from three of them for SugarCube. The snippets use SugarCube selectors and simplified layouts rather than reproducing the original stylesheets verbatim.
Open the <a href="https://drrosiegraham.com/interactive/twine/visual-techniques.html" target="_blank" rel="noopener">companion visual techniques guide</a> alongside Twine for screenshots, colour swatches and CSS demonstrations. It is a separate web page, so downloading the Twee file does not download the companion.
[[Howling Dogs: stark minimalism|5 Howling Dogs]]
[[With Those We Love Alive: gradient and color-coded links|5 WTWLA]]
[[Quing's Quest VII: retro adventure aesthetic|5 Quings Quest]]
<div class="section-footer">[[Back to Map|Map]]</div><h2>Howling Dogs (Porpentine, 2012)</h2>
Howling Dogs uses almost no custom CSS. The visual power comes from what is absent: no sidebar, no decoration, no competing interface. The text is alone on a black field. Everything has to work through the prose.
<span class="label-code">StoryStylesheet - stark dark aesthetic</span>
<span class="code-box"><nowiki>body {
background-color: #000000;
color: #ffffff;
font-family: Verdana, sans-serif;
font-size: 16px;
line-height: 1.9;
}
#story {
margin: 0 auto !important; /* reclaim the hidden sidebar's space */
max-width: 660px;
}
#passages {
border: none;
padding: 3em 2em;
margin-left: 0 !important;
}
/* Remove all sidebar chrome */
#ui-bar {
display: none;
}
a.link-internal {
color: #4d6ad8;
text-decoration: none;
}
a.link-internal:hover {
color: #8ea6ff;
}</nowiki></span>
<span class="note">Hiding the sidebar removes the history and restart buttons. Porpentine makes this choice deliberately: Howling Dogs does not want you to go back. If you want to keep restart, use <code>#ui-bar-history { display: none; }</code> to hide only the navigation arrows.</span>
<div class="section-footer">[[Back to Section 5|5 Games]]   [[Next: With Those We Love Alive|5 WTWLA]]</div><h2>With Those We Love Alive (Porpentine, 2014; music by Brenda Neotenomie)</h2>
WTWLA opens with an instruction: "Purple links change. Pink links move forward." The game teaches you its visual grammar before you play a single passage. The example below simplifies one of the game's darker dream palettes; its gradient stops and layout have been adapted for SugarCube. The companion guide also shows the game's cyan-to-plum base palette.
''The gradient background''
<span class="code-box"><nowiki>body {
background: linear-gradient(
to bottom,
rgba(0, 50, 53, 1) 0%, /* dark teal */
rgba(18, 0, 25, 1) 38%, /* deep purple */
rgba(0, 0, 0, 1) 65% /* black */
);
background-attachment: fixed;
color: #ffffff;
font-family: 'Open Sans', Verdana, sans-serif;
font-size: 20px;
line-height: 1.9;
margin: 0;
}
#story {
margin: 0 auto !important; /* reclaim the hidden sidebar's space */
max-width: 660px;
}
#passages {
margin: 80px 0 0 80px !important;
border: none;
}
.passage {
max-width: 620px;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.6);
}
#ui-bar { display: none; }</nowiki></span>
<span class="note">To use Open Sans, add this to your PassageHeader passage (not the stylesheet): <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap"></span>
''Adapting the link colours''
Pink navigation and purple cycling links follow the game. Its stylesheet also defines a green rule that is unused in play. Here, green is a teaching adaptation to distinguish text reveals.
<span class="code-box"><nowiki>/* Pink: navigation (default link color) */
a.link-internal {
color: #ea6ab9;
font-size: 1.2em;
text-decoration: none;
}
a.link-internal:hover { color: #f095cd; }
/* Green: a teaching adaptation for reveals
In passage: <span class="reveal-link"><<linkappend "text">>...<</linkappend>></span> */
.reveal-link a { color: #6aea9b; }
/* Purple: changes/cycles
In passage: <span class="cycle-link"><<cycle "$var">><<option ...>><</cycle>></span> */
.cycle-link a { color: #cf97f0; }</nowiki></span>
<span class="label-result">In passage text</span>
<span class="demo-box"><nowiki>[[Leave the workshop]] <-- pink by default
<span class="reveal-link"><<linkappend "Something catches your eye.">>
There is a knife on the workbench.
<</linkappend>></span> <-- green
<span class="cycle-link"><<cycle "$mood" autoselect>>
<<option "curious">><<option "wary">><<option "certain">>
<</cycle>></span> <-- purple</nowiki></span>
<div class="section-footer">[[Back to Section 5|5 Games]]   [[Next: Quing's Quest VII|5 Quings Quest]]</div><h2>Quing's Quest VII (Dietrich Squinkifer, 2014)</h2>
Where Porpentine reaches for atmospheric darkness, Squinkifer reaches for excess. The game riffs on King's Quest - old-school adventure conventions, room titles, inventory - refracting them through a queer political lens. You are a monarch of "mysterious and indistinct gender" exiled from their home planet on a ship called the Social Justice Warrior. The lavishness is the argument.
The key techniques: hot pink body text (<code>#D10E78</code>), lime green links (<code>#A1EE10</code>), an animated starfield GIF background, and Comic Neue Angular - a bold oblique variant of Comic Neue - with <code>font-variant: small-caps</code>. Nothing here is accidental.
''Font and color as political attitude''
<span class="code-box"><nowiki>/* Add Comic Neue to your PassageHeader passage:
<link href="https://fonts.googleapis.com/css2?family=Comic+Neue:ital,wght@1,700&display=swap" rel="stylesheet">
Background note: Quing's Quest uses an animated starfield GIF.
If you export your game and put an image in the same folder,
you can reference it as: background: url('your-image.gif');
*/
body {
background-color: #000;
color: #D10E78; /* hot pink -- body text, not links */
font-family: 'Comic Neue', 'Comic Sans MS', cursive;
font-weight: 700;
font-style: italic;
font-variant: small-caps; /* renders lowercase as small capitals */
font-size: 1.2em;
line-height: 1.6;
margin: 4% 2%;
}
#story {
margin: 0 auto !important; /* reclaim the hidden sidebar's space */
max-width: 660px;
}
#passages {
border: none;
padding: 0;
margin: 0 auto;
width: 96%;
}
#ui-bar { display: none; }
/* Links are lime green */
a.link-internal {
color: #A1EE10;
text-decoration: none;
}
/* Hover: yellow with a glow */
a.link-internal:hover {
color: #FFFD11;
text-shadow: #FFFD11 0 0 0.09em;
}</nowiki></span>
<span class="label-result">In passage text</span>
<span class="demo-box"><nowiki>You are in your Captain's Quarters. To the north is your [[closet]].
To the west is your [[en-suite bathroom]].
A door to the south leads out to the [[promenade]].</nowiki></span>
<span class="note">Notice: body text is hot pink, links are lime green. This inverts the usual convention where body is neutral and links are colored. The <code>font-variant: small-caps</code> gives the all-caps look without shouting. The result reads as a game world, not a website - which is exactly the point.</span>
<div class="section-footer">[[Back to Section 5|5 Games]]   [[Next: Mechanics Examples|6 Mechanics]]</div><h2>Section 6: Mechanics Examples</h2>
Three games that make a specific mechanic visible. None of these are on the Week 5 reading list, but each demonstrates something in SugarCube that the course games don't show as clearly.
[[Queers in Love at the End of the World: timed navigation|6 Queers in Love]]
[[Depression Quest: visible unavailability|6 Depression Quest]]
[[Typewriter effect: <<type>>|6 Typewriter]]
<div class="section-footer">[[Back to Map|Map]]   [[Next: Advanced Techniques|7 Advanced]]</div><h2>Queers in Love at the End of the World (Anna Anthropy, 2013)</h2>
The entire game runs for ten seconds. A countdown ring ticks down. When it reaches zero you are taken to an end passage - regardless of what you chose, or didn't. The game is about the feeling of not having enough time.
Here is a SugarCube adaptation of one part of that effect: a timeout within a single passage. The <code><<timed>></code> macro can run <code><<goto>></code> after a delay. Leaving the passage cancels the timer, so this example does not reproduce the original game's ten-second limit across multiple choices or its countdown ring.
''The technique: a single-passage timeout''
<span class="code-box"><nowiki><<timed 10s>>
<<goto "The End">>
<</timed>>
In the end, like you always said, it's just the two of you together.
If you stay here, the story moves to The End after ten seconds.
[[Leave before the timeout|Another Passage]]</nowiki></span>
<span class="note">Create passages named <code>The End</code> and <code>Another Passage</code> before trying this example. Following the link cancels this passage's timer. A whole-game countdown needs a deadline that continues to be checked after navigation.</span>
You can use <code><<timed>></code> for other effects too - revealing text within a passage after a delay:
<span class="code-box"><nowiki><<timed 2s>>A sound. Closer than you expected.<</timed>>
<<timed 4s>>[[Turn around|TurnAround]]<</timed>></nowiki></span>
<span class="note">Use seconds (<code>10s</code>) or milliseconds (<code>500ms</code>) for the delay. Write one minute as <code>60s</code>. Timed reveals inside a passage are a good way to control reading pace without forcing a link click. Use sparingly - readers who want to re-read will be frustrated if text keeps disappearing.</span>
<div class="section-footer">[[Back to Section 6|6 Mechanics]]   [[Next: Depression Quest|6 Depression Quest]]</div><h2>Depression Quest (Zoe Quinn, Patrick Lindsey, Isaac Schankler, 2013)</h2>
At the end of each passage in Depression Quest you see a numbered list of choices. Some are active links. Some are crossed out in red. The crossed-out options are things your character cannot do - not because they don't exist in the world, but because depression makes them inaccessible.
The crucial design choice: the unavailable options are not hidden. You can read them. You just can't click them.
''The technique: visible unavailability with <del> and <<if>>''
<span class="code-box"><nowiki>/% Set a depression variable in StoryInit: <<set $depression to 3>> %/
/% Higher = less depressed; lower = more restricted %/
Do you...
<<if $depression gte 5>>
[[Order food and work through the night|WorkHard]]
<<else>>
<del>Order food and work through the night</del>
<</if>>
[[Try to make yourself sit at your desk|DesksWork]]
[[Turn on the TV|TV]]
[[Crawl into bed|Bed]]
<div class="state-display">Your depression level: <<print $depression>></div></nowiki></span>
<span class="label-code">StoryStylesheet - unavailable options</span>
<span class="code-box"><nowiki>del {
color: #D11D10;
text-decoration: line-through;
display: block;
margin: 0.3em 0;
}
.state-display {
background: #c8c8c8;
color: #333;
padding: 0.5em 1em;
margin-top: 1em;
border-left: 2px solid #aaa;
}</nowiki></span>
<span class="note">The HTML <code><del></code> tag means "deleted content" - it automatically renders with a strikethrough. You don't need any CSS for the line-through; just the color change is custom. The emotional effect comes entirely from showing the thing the player cannot do. Ask yourself: should your inaccessible options be hidden or shown?</span>
<div class="section-footer">[[Back to Section 6|6 Mechanics]]   [[Next: Typewriter Effect|6 Typewriter]]</div><h2><<type>> - Typewriter Text Reveal</h2>
SugarCube 2 has a built-in macro that reveals text character by character, like a typewriter. This is not from a specific source game - it is a feature of the story format. But the effect it creates connects to something you can feel in several of the Week 5 games: the sense that words are arriving rather than already being there.
''The technique: <<type speed>>text<</type>>''
<span class="code-box"><nowiki>/% speed is milliseconds per character %/
/% 40ms = fast; 120ms = slow and deliberate %/
<<type 40ms>>You have been in this room for a very long time.<</type>>
<<type 120ms>>The walls are the same colour as forgetting.<</type>></nowiki></span>
You can type links, and you can chain multiple <code><<type>></code> blocks - they play in sequence:
<span class="code-box"><nowiki><<type 60ms>>There is a door.<</type>>
<<type 60ms start 1s>>It is [[open|Door]].<</type>></nowiki></span>
The <code>start</code> option sets the pause before typing begins. Use it to create a pause between lines.
<span class="note">The <code><<type>></code> macro requires SugarCube 2.32.0 or above. If you are exporting from Twine 2 with a recent SugarCube version (check the story format under Story > Details) it will work. Very long passages are frustrating to type out - use it for short, emphatic lines. Once text has typed out, it stays on screen; it does not disappear.</span>
<div class="section-footer">[[Back to Section 6|6 Mechanics]]   [[Next: Advanced Techniques|7 Advanced]]</div><h2>Section 7: Advanced Techniques</h2>
These techniques go beyond CSS and basic macros. Each one is optional - you don't need any of them for Assessment 2. But they open up possibilities that are hard to achieve otherwise.
[[Persistent sidebar with StoryCaption|7 Sidebar]]
[[Sound with <<audio>>|7 Audio]]
[[Conditional CSS classes: visual state changes|7 CSS Classes]]
[[Reusable components with <<widget>>|7 Widget]]
<div class="section-footer">[[Back to Map|Map]]   [[Quick Reference|Quick Reference]]</div><h2>Persistent UI - StoryCaption and PassageHeader/Footer</h2>
By default SugarCube gives you a sidebar with built-in controls. You can put your own content in that sidebar - anything you want visible on every passage - by creating a passage called exactly <strong>StoryCaption</strong>. SugarCube will put whatever is in that passage into the sidebar automatically.
Two other special passages add content to every passage in the main area:
<span class="demo-box">StoryCaption - appears in the sidebar on every passage
PassageHeader - appears at the top of every passage's main content
PassageFooter - appears at the bottom of every passage's main content</span>
''Using StoryCaption for inventory and stats''
<span class="code-box"><nowiki>/% Create a passage called: StoryCaption %/
/% Everything here appears in the sidebar %/
<div class="sidebar-label">Day</div>
<div class="sidebar-stat"><<print $day>></div>
<div class="sidebar-label">Location</div>
<div class="sidebar-stat"><<print $location>></div>
<<if $hasKey>>
<div class="sidebar-stat item">[key]</div>
<</if>></nowiki></span>
<span class="label-code">StoryStylesheet - sidebar styling</span>
<span class="code-box"><nowiki>/* Hide the default UI bar chrome, but keep #story-caption.
#story-caption lives inside #ui-bar-body, so hiding the whole
body would hide your own sidebar content too. Hide only the
parts you do not want: */
#title { display: none; } /* story title banner */
#menu { display: none; } /* saves, restart, settings */
#ui-bar-history { display: none; } /* back and forward arrows */
/* Style your StoryCaption content */
#story-caption .sidebar-label {
color: #505068;
font-size: 0.75em;
text-transform: uppercase;
letter-spacing: 0.1em;
margin: 1.2em 0 0.2em 0;
display: block;
}
#story-caption .sidebar-stat {
color: #9090b8;
}</nowiki></span>
''Using PassageFooter for persistent navigation''
<span class="code-box"><nowiki>/% Create a passage called: PassageFooter %/
<hr>
[[Map|Map]]   [[Journal|Journal]]   [[Inventory|Inventory]]</nowiki></span>
<span class="note">StoryCaption is live - it re-renders every time you navigate to a new passage. So <code><<print $variable>></code> inside it always shows the current value. You can use <code><<if>></code> inside it too: show a compass only when you are in the outdoor section, or show a health meter only when health matters.</span>
<div class="section-footer">[[Back to Section 7|7 Advanced]]   [[Next: Sound|7 Audio]]</div><h2>Sound - <<cacheaudio>> and <<audio>></h2>
SugarCube can play sound. Two macros do most of the work. <code><<cacheaudio>></code> loads a track and gives it a name, and <code><<audio>></code> plays, stops, loops, and fades it. This section shows the syntax only. No sound files ship with this tutorial, so the examples will stay silent until you supply your own audio and host it alongside your game.
''Load a track once''
<span class="code-box"><nowiki>/% StoryInit is the best place to cache your tracks %/
<<cacheaudio "rain" "media/rain.mp3" "media/rain.ogg">></nowiki></span>
Give the track an id ("rain") and one or more source files. Include more than one format where you can, because no single format plays in every browser. Paths are relative to your exported game, so <code>media/rain.mp3</code> means a <code>media</code> folder sitting next to your HTML file.
''Play, loop, and fade it''
<span class="code-box"><nowiki>/% Start a quiet, looping ambient bed %/
<<audio "rain" loop volume 0.5 play>>
/% Stop it, or fade it out over five seconds %/
<<audio "rain" stop>>
<<audio "rain" fadeout>></nowiki></span>
The first word after <code><<audio>></code> is the track id. Everything after it is a list of actions: <code>play</code>, <code>stop</code>, <code>pause</code>, <code>loop</code>, <code>volume</code> (0 to 1), <code>fadein</code>, and <code>fadeout</code>, among others.
<span class="note">Browsers will not let a sound start on its own before the reader has interacted with the page, so a track told to play the instant the game loads may stay silent until the first click. Start ambient sound on a link or an early choice, not on the opening passage. One low loop, used with restraint, does more for atmosphere than any amount of volume.</span>
<div class="section-footer">[[Back to Section 7|7 Advanced]]   [[Next: Conditional CSS Classes|7 CSS Classes]]</div><h2>Conditional Styling - <<addclass>> and <<removeclass>></h2>
You can change the visual appearance of the whole page - or any element on it - by adding and removing CSS classes. Define what each class does in the StoryStylesheet, then trigger it from passage code.
''The technique: <<addclass "selector" "classname">>''
<span class="label-code">StoryStylesheet - define mood classes</span>
<span class="code-box"><nowiki>/* Default: dark, neutral */
body { background: #09090f; color: #ccc8c4; }
/* "danger" class: red cast, urgent feel */
body.danger { background: #1a0000; }
body.danger .passage { color: #ffcccc; }
body.danger a.link-internal { color: #ff6666; }
/* "memory" class: sepia tone for flashback passages */
body.memory .passage {
filter: sepia(60%);
font-style: italic;
color: #c8b88a;
}</nowiki></span>
<span class="label-code">StoryInit - the starting state</span>
<span class="code-box"><nowiki><<set $inDanger to false>></nowiki></span>
<span class="label-code">PassageHeader - apply the current state on every passage</span>
<span class="code-box"><nowiki><<if $inDanger>>
<<addclass "body" "danger">>
<</if>></nowiki></span>
<span class="label-code">Alarm passage - enter the danger state</span>
<span class="code-box"><nowiki><<set $inDanger to true>>
<<addclass "body" "danger">>
The alarm is sounding. The lights have gone red.
[[Run|Escape]]</nowiki></span>
<span class="label-code">Escape passage - end the danger state</span>
<span class="code-box"><nowiki><<set $inDanger to false>>
<<removeclass "body" "danger">>
You made it through the door. The alarm stops.</nowiki></span>
<span class="note">Put each block in the place named above it. SugarCube clears body classes when you navigate to another passage. The story variable keeps the danger state, and PassageHeader reapplies its class on each turn. The alarm and escape passages also update the class immediately, after changing the variable. <<toggleclass>> adds or removes a class in the current page; it does not store a story state.</span>
<div class="section-footer">[[Back to Section 7|7 Advanced]]   [[Next: Widgets|7 Widget]]</div><h2>Reusable Components - <<widget>></h2>
If you write the same passage code in multiple places - a status bar, an inventory display, a recurring location header - you can define it once as a widget and call it anywhere.
Widgets live in a passage that you tag with the word <code>widget</code> (add it in the Tags field in the Twine editor).
''Defining a widget''
<span class="code-box"><nowiki>/% This passage is tagged "widget" in Twine %/
<<widget "statusbar">>
<div class="status-bar">
Day <<print $day>>  
<<print $location>>  
<<if $hasKey>>[key]<</if>>
</div>
<</widget>></nowiki></span>
''Calling the widget in any passage''
<span class="code-box"><nowiki><<statusbar>>
You are at the edge of the forest.
[[Go deeper|Forest2]] | [[Turn back|Town]]</nowiki></span>
Widgets can accept arguments, which you access inside as <code>_args[0]</code>, <code>_args[1]</code>, and so on:
<span class="code-box"><nowiki>/% Widget that takes a name and speaks it %/
<<widget "npc_says">>
<div class="npc-line">"<<print _args[0]>>," says <<print _args[1]>>.</div>
<</widget>>
/% Calling it %/
<<npc_says "I've been waiting for you" "the keeper">></nowiki></span>
<span class="note">Widgets are powerful for games with repeated structural patterns: each room in a location-based game might call a <code>room-header</code> widget; each character might have a <code>npc-portrait</code> widget. If you change the widget definition, it changes everywhere it is called. This is the same principle as functions in programming.</span>
<div class="section-footer">[[Back to Section 7|7 Advanced]]   [[Next: Images and Packaging|8 Images]]   [[Quick Reference|Quick Reference]]</div><h2>Section 8: Images and a Project You Can Hand In</h2>
An image in your passage can come from a file beside your game, an image embedded inside it, or a web address. These behave differently when you move the project to another computer.
For a project with several images, I recommend a folder containing the exported game and its image files, zipped together. The reader can extract the ZIP and play without fetching those images from the internet. Publishing an HTML file does not automatically collect the pictures it refers to.
<span class="demo-box"><img class="tutorial-image" data-passage="Tutorial Room Image" alt="An empty room with a blue window on the left and a closed door on the right.">This illustration is embedded in the tutorial, so it travels with the downloadable Twee file too.</span>
[[Two ways to put an image in a passage|8 Image Syntax]]
[[Package your game and images as a ZIP|8 Packaging]]
[[Optional: embed a few small images in one HTML file|8 Embedded Images]]
<a href="https://drrosiegraham.com/interactive/twine/image-example.zip" download>Download the working image-project ZIP</a>. Extract it, then open <code>index.html</code>. It includes the image, a short story, its editable Twee source and instructions.
<div class="section-footer">[[Back to Map|Map]]   [[Next: Image syntax|8 Image Syntax]]</div><h2>Two Ways to Display an Image</h2>
Both examples below load the same file. They do not copy the image into the HTML. Keep the file in the <code>images</code> folder beside your exported <code>index.html</code>.
''HTML: useful when you want a class or caption''
<span class="code-box"><nowiki><figure>
<img class="story-image" src="images/room.svg"
alt="An empty room with a blue window and a closed door.">
<figcaption>The room is waiting for someone.</figcaption>
</figure></nowiki></span>
The <code>alt</code> text describes what matters in the image for someone who cannot see it. Use <code>alt=""</code> for a purely decorative image. Keep information needed to make a choice in the passage text as well.
''SugarCube image shorthand''
<span class="code-box"><nowiki>[img[An empty room with a blue window and a closed door.|images/room.svg]]</nowiki></span>
The optional text before the pipe is an image title in the SugarCube version used by this guide; it does not set an explicit <code>alt</code> attribute. Use the HTML version above when the image carries information, so you can supply alternative text directly. The part after the pipe is the file path.
''Keep images within the screen''
Put this in Story > Stylesheet:
<span class="code-box"><nowiki>.story-image, .passage img {
display: block;
max-width: 100%;
height: auto;
margin: 1em auto;
}
figure { margin: 1em 0; }</nowiki></span>
The example uses SVG, a vector image format. You can use a suitable PNG, JPEG or WebP file instead: change the filename and extension in the passage to match your actual file. Resize large pictures before adding them, and credit images you did not make yourself. Use images you have permission to include in your submitted project.
<div class="section-footer">[[Back to Section 8|8 Images]]   [[Next: Make the ZIP|8 Packaging]]</div><h2>Package Your Game and Images</h2>
''1. Make one project folder.''
Use this arrangement. In the ZIP, <code>index.html</code> and the <code>images</code> folder should sit at the top level:
<span class="code-box"><nowiki>index.html
images/
room.svg
portrait.jpg
credits.txt</nowiki></span>
The second image and credits file are examples, not required filenames. Keep names simple, preferably lowercase with hyphens. Match capital letters exactly: <code>Portrait.jpg</code> and <code>portrait.jpg</code> can behave differently after upload.
''2. Use paths relative to your exported game.''
<span class="code-box"><nowiki><img src="images/portrait.jpg" alt="The keeper at the archive desk."></nowiki></span>
That means: start beside <code>index.html</code>, open <code>images</code>, then find <code>portrait.jpg</code>. Do not use a path from your own computer such as <code>C:\Users\...</code> or <code>/Users/...</code>, and do not start the path with <code>/images/</code>. A Google Drive sharing link is not an image file path. A picture hosted on someone else's website needs internet access and may change or disappear.
''3. Export into that folder.''
In Twine, choose Build > Publish to File. Save the result as <code>index.html</code> beside <code>images</code>. Export again after changing your story; the older HTML does not update when you edit in Twine.
<span class="note">Twine's Play and Test previews can run from a temporary location, where these relative image paths may not resolve. For the folder method, check the published HTML beside its images. A missing picture in the editor preview does not, by itself, prove your packaged project is broken.</span>
''4. Zip the files together.''
Select <code>index.html</code>, <code>images</code> and any other files the game needs, then use your computer's Compress or ZIP option. Keep their arrangement intact. Give the ZIP a clear project name. For an itch.io HTML game, <code>index.html</code> belongs at the ZIP's top level; do not put everything inside an extra outer folder first.
''5. Test the actual ZIP.''
Extract a fresh copy somewhere else, such as a new folder on your Desktop, and open the extracted <code>index.html</code>. Do not open the HTML from inside the compressed archive. Check every passage containing an image. Try the extracted copy without an internet connection to check that it contains the files it needs. Relative image paths work because you moved the folder structure together.
''6. Keep the editable work too.''
Keep your Twine archive or Twee source backed up separately. The playable hand-in is the published HTML plus its assets; a Twee file is source for Twine to import. Include editable source in the submission if the assessment brief asks for it. Follow that brief for the required format, size limit and any reflection or credits.
<a href="https://drrosiegraham.com/interactive/twine/image-example.zip" download>Download and inspect the working example ZIP</a>. It needs no image hosting or separate installation. For online sharing, see <a href="https://itch.io/docs/creators/html5" target="_blank" rel="noopener">itch.io's HTML game upload instructions</a>.
<div class="section-footer">[[Back to Section 8|8 Images]]   [[Next: Embedded images|8 Embedded Images]]</div><h2>Optional: Put the Image Inside the Story</h2>
For a few small images, SugarCube can store the image data in a specially tagged passage. It then travels inside the exported HTML and the Twee source. This is useful when you really need one file. A large image collection will make the story harder to edit and much bigger; the ZIP method is usually easier to manage.
''1. Turn the image into a data URI.''
Open the <a href="https://drrosiegraham.com/interactive/twine/image-to-data-uri.html" target="_blank" rel="noopener">local image converter</a> and choose an image. It reads the file in your browser without uploading it. You can download the converter page and use it offline. Copy the complete result, beginning with something like <code><nowiki>data:image/png;base64,</nowiki></code>.
''2. Create an image passage.''
Create a passage named <code>Room Image</code>. Give it the tag <code>Twine.image</code>, with exactly that capitalisation and no other tags. Paste the complete data URI into its content, with no surrounding code or explanation. Do not link to this passage as a room in your story.
''3. Refer to it from a normal passage.''
Use HTML to set alternative text and a class explicitly:
<span class="code-box"><nowiki><img class="story-image" data-passage="Room Image"
alt="An empty room with a blue window and a closed door."></nowiki></span>
SugarCube's compact alternative is <code><nowiki>[img[Room Image]]</nowiki></code>. As with file-based images, use HTML when the image needs alternative text.
In the imported tutorial, open <code>Tutorial Room Image</code> to see a complete working example. It contains only the encoded illustration used in Section 8. For this embedded-image method, Play and Test do not need a separate image folder.
Keep the original image file somewhere safe so you can edit it later. Once you publish, move a copy of the HTML away from its original folder and check that the image still appears. Read <a href="https://www.motoslave.net/sugarcube/2/docs/#guide-media-passages" target="_blank" rel="noopener">SugarCube's media-passage documentation</a> for the full method and its limits.
<div class="section-footer">[[Back to Section 8|8 Images]]   [[Next: Testing and Debugging|9 Debugging]]   [[Quick Reference|Quick Reference]]</div>data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2NDAgMzYwIiB3aWR0aD0iNjQwIiBoZWlnaHQ9IjM2MCI+PHJlY3Qgd2lkdGg9IjY0MCIgaGVpZ2h0PSIzNjAiIGZpbGw9IiMyNDJiM2EiLz48cGF0aCBkPSJNMCAyODBINjQwVjM2MEgwWiIgZmlsbD0iIzQzNDA0YSIvPjxwYXRoIGQ9Ik0wIDI4MEg2NDAiIHN0cm9rZT0iI2I5YjFhOCIgc3Ryb2tlLXdpZHRoPSIzIi8+PHJlY3QgeD0iNzUiIHk9IjY1IiB3aWR0aD0iMTY1IiBoZWlnaHQ9IjE0NSIgZmlsbD0iIzkxYmJkNCIgc3Ryb2tlPSIjZDJjOGI4IiBzdHJva2Utd2lkdGg9IjkiLz48cGF0aCBkPSJNMTU4IDY5VjIwNk04MCAxMzhIMjM1IiBzdHJva2U9IiNkMmM4YjgiIHN0cm9rZS13aWR0aD0iNiIvPjxyZWN0IHg9IjQxMCIgeT0iODAiIHdpZHRoPSIxMzAiIGhlaWdodD0iMjAwIiBmaWxsPSIjOGM2YjUzIiBzdHJva2U9IiNkMmM4YjgiIHN0cm9rZS13aWR0aD0iNSIvPjxjaXJjbGUgY3g9IjUxOCIgY3k9IjE4OCIgcj0iNiIgZmlsbD0iI2Y2ZDk5NiIvPjwvc3ZnPg==<h2>Section 9: Testing and Debugging</h2>
A story can run without an error message and still make the wrong choice. Start with a small question: what did I expect to happen, and what happened instead?
''A fault to find''
Suppose the reader has found a key, but the door stays locked:
<span class="code-box"><nowiki><<set $hasKey to true>>
<<if $hasKee>>
[[Open the door|Archive]]
<<else>>
The door is locked.
<</if>></nowiki></span>
The code sets <code><nowiki>$hasKey</nowiki></code> but checks <code><nowiki>$hasKee</nowiki></code>. Those are different names. An unset variable can produce the wrong branch without a helpful red error. Correct the condition to <code><nowiki><<if $hasKey>></nowiki></code>. Match capital letters too.
If a link instead reports that its destination does not exist, compare the target with the passage name, including spaces and capitals. A missing passage and a misspelt variable are different faults.
''A repeatable way to investigate''
<ol class="howto-list"><li>Reproduce the problem with the same sequence of choices.</li><li>Write down the passage and the variable you expect to change.</li><li>Use Test mode to inspect that value before and after the choice.</li><li>Change one thing, then repeat the route from a fresh start.</li></ol>
[[Watch a variable and test a boundary|9 Watches]]
[[Use the pre-submission checklist|9 Checklist]]
<div class="section-footer">[[Back to Map|Map]]   [[Next: Variable watches|9 Watches]]</div><h2>Watch What the Story Remembers</h2>
Import this guide into Twine, select SugarCube as its format, then choose Build > Test. SugarCube adds a debug bar with variable watches and a history of turns. Open Watch, add <code><nowiki>$clues</nowiki></code>, and follow the example below. The value should change when you choose a link. You can hide debug Views if their extra labels make the page hard to read.
In your own story, put starting values in the special passage <code>StoryInit</code>:
<span class="code-box"><nowiki><<set $clues to 0>></nowiki></span>
StoryInit runs before the first passage, including when you use Passage > Test From Here. Testing a later passage skips the earlier choices that would normally lead there. It gives you the starting values, not a completed playthrough. Test the full route as well.
''Check the edge of a condition''
This example requires at least two clues:
<span class="code-box"><nowiki><<if $clues >= 2>>
You can explain what happened.
<<else>>
You need another clue.
<</if>></nowiki></span>
[[Try the working clues example|9 Clues]]
Choose one clue, then two. The first should say you need another clue; the second should let you explain. If you change the threshold, test just below it and exactly on it. Testing only a high value can hide an off-by-one error.
Read <a href="https://twinery.org/reference/en/publishing/testing.html" target="_blank" rel="noopener">Twine's testing instructions</a> and <a href="https://www.motoslave.net/sugarcube/2/docs/#guide-test-mode" target="_blank" rel="noopener">SugarCube's Test Mode guide</a> for the controls in your version.
<div class="section-footer">[[Back to Section 9|9 Debugging]]   [[Next: Submission checks|9 Checklist]]</div><h2>How Many Clues?</h2>
Choose a value, then inspect the result. These links set the variable before moving to the result passage.
<<link "Find one clue" "9 Clues Result">><<set $clues to 1>><</link>>
<<link "Find two clues" "9 Clues Result">><<set $clues to 2>><</link>>
<div class="section-footer">[[Back to variable watches|9 Watches]]</div><h2>The Result</h2>
Clues found: <<print $clues>>.
<<if $clues >= 2>>You can explain what happened.<<else>>You need another clue.<</if>>
[[Try the other value|9 Clues]]
<div class="section-footer">[[Back to variable watches|9 Watches]]   [[Submission checks|9 Checklist]]</div><h2>Before You Hand It In</h2>
<ul class="howto-list"><li>Start a fresh playthrough. Visit every ending and every conditional branch, including a choice that should be unavailable.</li><li>Check every link. Make any deliberate ending clear, so a reader can distinguish it from a broken route.</li><li>Check variables before and after choices. A value that increases on entry to a passage may increase again when the reader returns.</li><li>Try going back, restarting and loading a save. [[Section 12|12 Saving]] explains what each does.</li><li>Ask someone to play without explaining the route. Note where they hesitate or misunderstand a choice.</li><li>Publish again after your final edit. Test that exported file, including its images and sound. For a ZIP, test a freshly extracted copy as in [[Section 8|8 Packaging]].</li><li>Keep an editable backup separately. A player's save is not a backup of the story you are writing.</li></ul>
An error report is more useful when it says "leave the ticket, then help with the case: the wrong ending appears" than "the ending is broken". Keep a short list of routes tried and the result of each.
<div class="section-footer">[[Back to Section 9|9 Debugging]]   [[Next: Accessibility|10 Accessibility]]</div><h2>Section 10: Accessibility and Reader Control</h2>
Atmosphere depends on how someone can read and act. A faint link, a disappearing choice or an unskippable typing effect can prevent them from reaching the story at all.
''Try this short inspection''
<ul class="howto-list"><li>Use Tab and Shift+Tab to reach choices, and Enter to activate them. You should always see which link or button has focus. Use real links and buttons rather than making a picture the only way forward.</li><li>Use descriptive choices such as "Open the archive", and do not communicate availability through colour alone. Explain why a choice is unavailable in text.</li><li>Check text against its background. Aim for at least 4.5:1 contrast for ordinary text. The deliberately dim atmosphere examples in this guide show an effect, not a suitable style for essential instructions.</li><li>Zoom to 200% and try a narrow phone window. Text, images and choices should remain readable without sideways scrolling.</li><li>Describe meaningful images with alternative text, and keep essential clues in the prose too. [[Section 8|8 Image Syntax]] shows the HTML.</li><li>Let readers choose an immediate version of delayed text. Keep navigation available while an effect runs. Avoid flashing, and offer an alternative to any timed challenge.</li><li>Make audio optional, with a visible stop or mute control. Never make sound the only way to understand a clue.</li></ul>
These checks are a starting point, not a claim that the whole game is accessible. Ask readers what worked for them. <a href="https://www.w3.org/WAI/test-evaluate/preliminary/" target="_blank" rel="noopener">W3C's Easy Checks</a> explains practical checks for headings, contrast, keyboard use and alternatives to images.
[[Build a choice of reading pace|10 Reader Control]]
<div class="section-footer">[[Back to Map|Map]]   [[Next: Reader controls|10 Reader Control]]</div><h2>Let the Reader Choose the Pace</h2>
Use a starting value that shows the text immediately. Put this in StoryInit, alongside your other starting values:
<span class="code-box"><nowiki><<set $instantText to true>></nowiki></span>
In a passage named <code>Reading Options</code>, offer two buttons:
<span class="code-box"><nowiki><<button "Read instantly" "Arrival">>
<<set $instantText to true>>
<</button>>
<<button "Try the typing effect" "Arrival">>
<<set $instantText to false>>
<</button>></nowiki></span>
In <code>Arrival</code>, put the navigation outside the effect:
<span class="code-box"><nowiki><<if $instantText>>
The light is still on. Someone has waited for you.
<<else>>
<<type 45ms>>The light is still on. Someone has waited for you.<</type>>
<</if>>
[[Change the reading pace|Reading Options]]</nowiki></span>
''Try it here''
<<button "Read instantly" "10 Reader Demo">><<set $instantText to true>><</button>>
<<button "Try the typing effect" "10 Reader Demo">><<set $instantText to false>><</button>>
This story variable travels with the playthrough: loading an older save or going back may restore its older value. For a small project that is enough; a preference that must apply across all playthroughs needs a separate settings system.
''Respect reduced-motion preferences''
Put this CSS in Story > Stylesheet:
<span class="code-box"><nowiki>a:focus-visible, button:focus-visible {
outline: 3px solid #f1cf84;
outline-offset: 4px;
}
@media (prefers-reduced-motion: reduce) {
.passage { animation: none; }
}</nowiki></span>
Choose a focus colour that stands out on your own background. The media query turns off the passage animation demonstrated earlier in this guide when the reader requests reduced motion. It does not disable SugarCube's timed or typing macros: the immediate-text option above handles that effect separately.
<div class="section-footer">[[Back to Section 10|10 Accessibility]]   [[Next: A complete mini-project|11 Mini-project]]</div><h2>Arrival</h2>
<<if $instantText>>
The light is still on. Someone has waited for you.
<<else>>
<<type 45ms>>The light is still on. Someone has waited for you.<</type>>
<</if>>
[[Change the reading pace|10 Reader Control]]
The link remains available while the text appears.
<div class="section-footer">[[Back to accessibility checks|10 Accessibility]]   [[Next: A complete mini-project|11 Mini-project]]</div><h2>Section 11: Make a Complete Small Story</h2>
''The Last Ferry'' connects two choices, two remembered values and two endings. Taking a ticket changes whether you can board. Helping a neighbour changes the prose at either ending. The routes join again, but the earlier choices still matter.
<span class="code-box"><nowiki>Quay: take or leave the ticket
|
Steps: help with the case or walk on
|
Departure: check whether you have a ticket
| |
Afloat Ashore
Each ending also checks whether you helped.</nowiki></span>
<<link "Play The Last Ferry inside this guide" "11 Quay">><<set $hasTicket to false>><<set $helped to false>><</link>>
<a href="https://drrosiegraham.com/interactive/twine/last-ferry.html" target="_blank" rel="noopener">Open the standalone game</a>, with SugarCube's normal save, history and restart controls. To keep it, save that page as HTML. It needs no separate images or internet connection once saved.
<a href="https://drrosiegraham.com/interactive/twine/last-ferry.twee" download>Download its editable Twee source</a>, then import it into Twine as a separate story. Select SugarCube if asked. This example has no additional assets to package.
[[See the full source and build your own version|11 Source]]
[[Test every route|11 Playtest]]
<div class="section-footer">[[Back to Map|Map]]   [[Next: Source and exercise|11 Source]]</div><h2>From Plan to Passages</h2>
Create five passages named <code>Quay</code>, <code>Steps</code>, <code>Departure</code>, <code>Afloat</code> and <code>Ashore</code>. Set Quay as the start passage. Create the special StoryInit passage for the starting values. These names belong to this standalone example; choose distinct names when adding it to an existing story.
The block below is Twee source. If you copy passages by hand, use each <code>::</code> heading as its name, and paste only the text below that heading into the passage. Put the StoryStylesheet content in Story > Stylesheet. In Twine, StoryTitle is the story's title and StoryData is import metadata; neither needs to be an ordinary passage. The downloadable file handles those details for you.
<span class="code-box"><nowiki> :: StoryTitle
The Last Ferry
:: StoryData
{"ifid":"C07B967F-A4C9-4EA2-A6F3-85E848786C09","format":"SugarCube","format-version":"2.37.3","start":"Quay"}
:: StoryInit
<<set $hasTicket to false>>
<<set $helped to false>>
:: StoryStylesheet [stylesheet]
body { font-family: Georgia, serif; line-height: 1.7; }
a:focus-visible, button:focus-visible {
outline: 3px solid #f1cf84;
outline-offset: 4px;
}
:: Quay
The last ferry leaves at dusk. There is a spare ticket on the bench.
<<link "Take the ticket" "Steps">><<set $hasTicket to true>><</link>>
<<link "Leave the ticket" "Steps">><<set $hasTicket to false>><</link>>
:: Steps
A neighbour is struggling with a heavy case.
<<link "Help carry the case" "Departure">><<set $helped to true>><</link>>
<<link "Walk on" "Departure">><<set $helped to false>><</link>>
:: Departure
<<if $hasTicket>>
The keeper checks your ticket.
[[Board the ferry|Afloat]]
<<else>>
The keeper shakes her head. No ticket, no crossing.
[[Stay on the quay|Ashore]]
<</if>>
:: Afloat
The shore begins to shrink.
<<if $helped>>
Your neighbour saves you a seat beside the window.
<<else>>
You find a seat alone.
<</if>>
The end. Use Restart in the sidebar to try another route.
:: Ashore
The ferry disappears into the mist.
<<if $helped>>
Your neighbour waves from the deck. You arrange to meet tomorrow.
<<else>>
You turn towards the empty road home.
<</if>>
The end. Use Restart in the sidebar to try another route.</nowiki></span>
''Your turn''
Change the setting, the object and what helping means. Keep the structure small enough to finish. Before writing, say what each choice records and where that value will be used. Add one consequence you can explain in a sentence.
The setters are inside the links so they run only when clicked, before entering the next passage. Putting both setters directly in the passage would run both as the passage was displayed.
Use StoryInit for defaults, not for resetting every scene. An ordinary link to Quay does not restart the whole story. In this guide, the launch link explicitly resets the two example variables so you can try again; the standalone game uses the built-in Restart control.
<div class="section-footer">[[Back to Section 11|11 Mini-project]]   [[Next: Test the routes|11 Playtest]]</div><h2>Test the Consequences, Not Just the Links</h2>
There are four combinations of the two choices. Play all four from a fresh start, and compare each result with this table:
<table class="route-table"><caption>Expected routes in The Last Ferry</caption><thead><tr><th scope="col">Ticket</th><th scope="col">Case</th><th scope="col">Expected result</th></tr></thead><tbody><tr><td>Take</td><td>Help</td><td>Afloat: a seat with the neighbour</td></tr><tr><td>Take</td><td>Walk on</td><td>Afloat: a seat alone</td></tr><tr><td>Leave</td><td>Help</td><td>Ashore: meet tomorrow</td></tr><tr><td>Leave</td><td>Walk on</td><td>Ashore: the empty road</td></tr></tbody></table>
In Test mode, watch <code><nowiki>$hasTicket</nowiki></code> and <code><nowiki>$helped</nowiki></code>. Each should be true or false. If an ending is wrong, trace which choice last set the relevant value.
Ask a partner to play without hints. Ask what they thought each choice would do, whether the consequences made sense, and where they expected another option. Record what happened before explaining your intention.
A deliberate ending can stop the story. An accidental dead end leaves the reader wondering whether something failed. Give endings a clear signal, and preserve a way to restart.
<div class="section-footer">[[Play or download the example|11 Mini-project]]   [[Next: Saves, restart and history|12 Saving]]</div><h2>Section 12: Saves, Restart and History</h2>
SugarCube normally provides these controls in its sidebar. They affect the playthrough, including the variables that record choices. Several visual recipes in this guide hide the sidebar; that also hides these controls. This tutorial hides its history arrows to keep the lesson navigation simple. Use the standalone mini-project below to try the normal interface.
<a href="https://drrosiegraham.com/interactive/twine/last-ferry.html" target="_blank" rel="noopener">Open The Last Ferry with its normal controls</a>.
''Going back''
Use SugarCube's own backward arrow to return to an earlier passage and its earlier variable values. This undoes the later choice for that point in the history. Choosing a different route from there replaces the future route. History is limited, so you cannot assume every earlier passage remains available.
An ordinary passage link such as <code><nowiki>[[Return to the quay|Quay]]</nowiki></code> visits Quay as a new turn. It does not undo later choices or restore old values. Your browser's Back button navigates browser pages, so use the game's controls for story history.
''Saving and loading''
Open Saves in the sidebar. A browser save stays in that browser's storage for this story. It is not stored in your Twine authoring file and does not automatically travel to another computer. Clearing site data or using private browsing can lose it. Where the Saves dialog offers a disk/file save or export, keep that file if you need a portable copy of progress; labels vary with SugarCube version.
Load a save to restore the recorded playthrough. Browser session restoration on refresh is separate from an explicit save: refreshing may resume the game rather than give you a clean start. Do not use refresh as your restart test.
''Restarting''
Use Restart in the sidebar and confirm it. This begins a new playthrough and runs StoryInit again. It does not delete saved games, so loading an old save can bring the old choices back. A link to the first passage alone does not do this reset.
[[Try a save, backtrack and restart exercise|12 Exercise]]
<div class="section-footer">[[Back to Map|Map]]   [[Next: State exercise|12 Exercise]]</div><h2>Prove That the State Changes</h2>
Use the <a href="https://drrosiegraham.com/interactive/twine/last-ferry.html" target="_blank" rel="noopener">standalone Last Ferry game</a>, so the normal controls are visible.
<ol class="howto-list"><li>Take the ticket. At Steps, save to an unused browser slot. Do not overwrite a save you want to keep.</li><li>Help with the case, then board. You should get the seat with the neighbour.</li><li>Use the game's backward arrow to return to Steps. Choose Walk on instead. Board again: the seat should now be alone.</li><li>Load the save from Steps. You should be back before the case choice, with the ticket still taken. Help again and check the neighbour ending.</li><li>Use Restart, then leave the ticket and walk on. You should stay ashore and take the empty road.</li></ol>
The code changes values in the choice link, then immediately moves to another passage. That gives SugarCube a new turn to record. If you change a variable while staying in the same passage, a save or restored turn can behave differently: the recorded turn starts with the values from when the passage was entered. For a first project, keep consequential choices together with passage navigation, as this example does.
If you hide the whole sidebar, keep an equally clear route to the controls your readers need, or leave it visible. Removing a control is a design decision with consequences for replay and recovery.
Read <a href="https://www.motoslave.net/sugarcube/2/docs/#guide-state-sessions-and-saving" target="_blank" rel="noopener">SugarCube's state, sessions and saving guide</a> for the fuller explanation. Player saves preserve progress. For your editable work, keep using Twine's Archive/export backups as explained in [[Getting Started|Getting Started]].
<div class="section-footer">[[Back to Section 12|12 Saving]]   [[Submission checks|9 Checklist]]   [[Quick Reference|Quick Reference]]</div>The last ferry leaves at dusk. There is a spare ticket on the bench.
<<link "Take the ticket" "11 Steps">><<set $hasTicket to true>><</link>>
<<link "Leave the ticket" "11 Steps">><<set $hasTicket to false>><</link>>A neighbour is struggling with a heavy case.
<<link "Help carry the case" "11 Departure">><<set $helped to true>><</link>>
<<link "Walk on" "11 Departure">><<set $helped to false>><</link>><<if $hasTicket>>
The keeper checks your ticket.
[[Board the ferry|11 Afloat]]
<<else>>
The keeper shakes her head. No ticket, no crossing.
[[Stay on the quay|11 Ashore]]
<</if>>The shore begins to shrink.
<<if $helped>>
Your neighbour saves you a seat beside the window.
<<else>>
You find a seat alone.
<</if>>
The end. [[Try another route|11 Mini-project]] or [[test the consequences|11 Playtest]].The ferry disappears into the mist.
<<if $helped>>
Your neighbour waves from the deck. You arrange to meet tomorrow.
<<else>>
You turn towards the empty road home.
<</if>>
The end. [[Try another route|11 Mini-project]] or [[test the consequences|11 Playtest]].