Twine SugarCube Cheatsheet
Twine SugarCube Cheatsheet
Versions
Twine 2.7.0
SugarCube 2.36.1
An all-in-one Twine SugarCube cheatsheet for easy navigation, CTRL + F, and copy-paste,
containing reference links and condensed tips to get interactive functionality and UI/UX started.
This is not an exhaustive list, but rather an overview of some common and useful syntax and
functions, with quick access to various forms of documentation. A few sources of custom macros
are included for ease of access.
Put this together for myself, because making giant lists helps me, but cleaned it up to share in case
anyone else might find it useful.
Twine Cookbook
SugarCube
SugarCube 2 Documentation
HTML
CSS
JavaScript
W3 Schools
HTML
CSS
JavaScript
Quick Code Generators & Templates
HTML-CSS-JS.com
CSS Portal
Toptal: Utilities
Twine Interface
Twinery: Story Format - Terms
Twinery: Story Formats - Editor
Twinery: Passages View
Twinery: Passages
All code and macros are meant to be used with the SugarCube story format and will go into one or
more of the following:
Passages
Twinery: Passages View
Twinery: Passages
Special Passages
StoryAuthor
StoryBanner
StoryCaption
StoryDisplayTitle
StoryInit
StoryInterface
StoryMenu
StoryShare
StorySubtitle
Passage Links
Uses wikilinks:
''Bolded text.''
//Italicized text.//
<ul>
<li>This is text</li>
<li>in a list.</li></ul>
Headers
!This is an H1 header.
!!!!!This is an H5 header.
Positioning
Button Macro
Timed Macro
Automatic Forwarding
--with delay:
Textbox Macro
Can be used to enter a variable (see "Narrative Options" below for more on variables):
--no prefill:
--prefill:
#textbox-player-name {
border-style: inset; }
Creating a textbox that enters a predetermined variable regardless of what is typed:
--see the "Typing Simulation" custom macro.
Various methods to fine-tune the appearance and configuration of line breaks and whitespace
within passages.
This is\
an example text.
This is
\example text.
The "silently" macro will discard any output between its tags:
--Can be used to enclose comments or macros that don't produce any visible output, so as to
format them for readability.
The "nobr" macro will remove line breaks but render output:
Tag a passage with nobr to configure that passage to render with single line breaks.
Put the "nobr" API within your JavaScript to render all passages with single line breaks by default:
Config.passages.nobr = true;
UI Bar In Passages
To properly load images for playtesting, save the story via "Publish To File" in game's folder, then
open the .html file from the game folder into a browser to see changes.
--Have an /images folder within your story folder to create the image path.
Audio
To properly load audio for playtesting, save the story via "Publish To File" in game's folder, then
open the .html file from the game folder into a browser to hear changes.
--Have an /audio folder within your story folder to create the audio path.
To loop:
To pause or stop:
To resume:
To reduce volume:
JavaScript
UI Bar & Settings
UIBar.destroy()
Config.ui.stowBarInitially = true;
Settings
Setting.addHeader("Settings");
Change text that is built into the UI, for localization purposes or personal preferences:
l10nStrings.savesTitle = "Checkpoints";
l10nStrings.restartTitle = "Redo";
Font Size
var settingFontSizeNames = ["Default", "Large"]; /*--- these are the names that
will show up in the settings menu; change or add extra font options here between
"[ ]" ---*/
var settingFontSizeHandler = function () {
var $html = $("html");
/*--- copy-paste to add more font sizes; remember to match the cnames in quotes
according to how they appear above and in the stylesheet ---*/
switch (settings.fontsize) {
case "Default":
$html.addClass("fontsize-default");
break; }
switch (settings.fontsize) {
case "Large":
$html.addClass("fontsize-large");
break; } };
Setting.addList("fontsize", {
label : "Change the font size.", /*--- "change the font size" can be
changed to desired text ---*/
list : settingFontSizeNames,
onInit : settingFontSizeHandler,
onChange : settingFontSizeHandler });
html.fontsize-default .passage {
font-size: 0.95em; }
html.fontsize-large .passage {
font-size: 1.2em; }
Audio Toggle
Fullscreen
Set up autosave:
--to automatically save on passages tagged with "autosave" or another desired tag.
Themes
var settingThemeNames = ["Light", "Dark"]; /*--- these are the names that will
show up in the settings menu; change or add extra theme options here between "[
]" ---*/
var settingThemeHandler = function () {
var $html = $("html");
/*--- copy-paste to add more themes; remember to match the cnames in quotes
according to how they appear above and in the stylesheet ---*/
switch (settings.theme) {
case "Light":
$html.addClass("theme-light");
break;
case "Dark":
$html.addClass("theme-dark");
break; } };
Setting.addList("theme", {
label : "Choose a theme.", /*--- "choose a theme" can be changed to
desired text ---*/
list : settingThemeNames,
onInit : settingThemeHandler,
onChange : settingThemeHandler });
/*--- make sure all theme names across your JavaScript and stylesheet match
exactly ---*
CSS Stylesheet
Themes
html.theme-one body {
attributes-here: attribute; }
html.theme-two body {
attributes-here: attribute; }
Use the root selector to standardize colors and styles for ease of editing:
:root {
--title-font: "Garamond", serif;
--body-font: "Arial", sans-serif;
--subtitle-font: "Georgia", serif;
--font-size-regular: 0.95em;
--font-size-title: 2em;
--font-size-subtitle: 1.1em;
--body-color: #f5f5f5;
--accent1: #ffcc00;
--accent2: #cc9900;
--fallback-color: #0f0c00;}
Background
Gradient background:
/*--- remove html.theme-name if not using themes; adjust the style of the
gradient (top right, bottom left, 45deg, etc) as desired ---*/
html.theme-name body {
background-attachment: fixed;
background-image: -webkit-linear-gradient(top right, #0f2027, #203a43,
#2c5364);
background-image: linear-gradient(top right, #0f2027, #203a43, #2c5364);
background-color: var(--color-name);
#ui-bar {
display: none; }
html.theme-name #ui-bar-history {
display: none; }
Other Styling
ul {
list-style-type: square; }
Narrative Options
Choice Tracking With Conditional Variables
Use $ to set variables. Set tracked variables in the StoryInit special passage or relevant story
passage.
If placing within StoryInit , set them as false initially:
If placing within a story passage, set them as true when and where the variable option is chosen:
<<nobr>>
You listen to the
<<if $radio>>radio
<<else>>silence
<</if>>.
<</nobr>>
<<unset $radio>>
<<nobr>>
What is your favorite fruit?
<<cycle "$fruit" autoselect>>
<<option "Strawberries">>
<<option "Apples">
<<option "Grapes">>
<<option "Bananas">>
<</cycle>>.
<</nobr>>
Twinelab / GitHub
Demos: Twinelab
The Fading Macro Set: A simple macro set that causes the text between its tags to fade in or
out over a period of time specified by the user, with an optional delay.
The Event Macro: This macro be used to handle events in your game; things like keyboard
hotkeys, controls, clickable non-link elements, and more. Note that the element the event is
tied to does not need to be rendered (or currently on the page or in the passage) in order to
attach an event to it.
The Continue Macro Set: Used to create basic "press any key" or "click anywhere to continue"
style interactions.
The First Macro: Creates code or text that is shown based on how many times the player has
visited a particular passage.
The Typing Simulation Macro: Creates a text area. When focused, the user's keystrokes
generate a predefined message one letter at a time, simulating typing but ignoring the actual
input. After the message is finished, any text or code between the macro tags is displayed /
run.
Hiev's Sample Code
Patreon / Other
Favicon
Combining Story Passages: Combine multiple linear (non-branching) story passages into a
single passage.
GitHub
Click To Proceed: Aims to provide an easy way to set up content that is revealed bit-by-bit via
user interaction.
Live Update: Used to show a change in a variable value without a passage transition.
More
Hogart on GitHub
Mikewesthad on GitHub
SugarCube Validator on Github: Validates SugarCube games, and finds bugs quickly and
easily.