An activity to introduce Twine in 45-60m. Twine is an open-source tool for telling interactive, nonlinear stories. The goal of this lesson is to build a simple interactive fiction story using Twine. It uses CSS for styling, and introduces variables as a way to keep track of information throughout a story.
Instructor Note: It may be beneficial to allow the students drive the story writing process. Take suggestions from them for the content of the story, the branches, the characters, etc. Make sure their suggestions are conducive to a story with at least one variable, and multiple branches reaching the same node.






Now that the story is setup up, it’s time to start writing it! Double click on the “Untitled Passage” node to begin editing it. Stories usually begin with the main character waking up. For example:
Your eyes slowly open. You check the clock, and see that it is 6:00am. Your bed is warm and cozy, but you know it’s time to start your day.
Adding an image to a story can make it much more dynamic and engaging.

[img[]] on its own line[ and ]), paste in the image URL with Ctrl+v
[img[https://www.ohsu.edu/sites/default/files/2019-06/insomnia-sleep.png]]
Currently, the story is not very interactive. To make it more fun, use links to allow the user to choose a path for the main character.
[[ and ]]
[[Wake up]][[Stay in bed]]You wake up and get out of bed, ready to face the day!You continue to sleep happily.Choose one of the paths, and add another pair of branches to continue the story. Use links [[like this]] to create the branching passages.
CSS (Cascading Style Sheets) is a styling language for the web. Almost every website uses CSS to change fonts, colors, layouts, and much more!
It is possible to demonstrate the use of CSS in Google Chrome using Chrome DevTools. This toolset allows developers to update CSS for a webpage right from the browser!
F12 key to open Chrome DevTools
+ button to create a new style rule
body
{ and })font-size: 20px, and press the Enter key
font-family: cursive
body {
font-size: 20px;
font-family: cursive;
}
These are only a couple of the styles in CSS. There are many more to explore!
Twine hosts stories on the web, so it is possible to use CSS to update the styles for those pages too!
font-size, font-family, text color, and background-color for the story:
body {
font-size: 20px;
font-family: consolas;
color: lightpink;
background-color: darkblue;
}
Some color names like “lightpink” and “darkblue” are built into the web already, but it is also possible to choose custom colors using RGB values! The RGB color model is an additive color model in which red, green and blue light are added together in various ways to reproduce a broad array of colors. Basically, it is possible to create any digital color with a combination of red, green, and blue!
Each color (R, G, and B) can take a number from 0 to 255. This represents the amount of the color in the mix. For example, a color with a Red value of 255, a Green value of 0, and a Blue value of 0 would be red.
The combinations are almost endless! Google has a built-in color picker that developers and designers can utilize to find the perfect color. It displays RGB colors in the HEX format like so:
#7b95a8
To use that color in CSS, copy the number (including the #) and paste it into the CSS where a color would go! Try out some different colors for the page to find the best ones.
Twine also allows developers to keep track of different details throughout the story using variables. For example, the story could track how much money the main character has, their health level, their age, the weather, the time of day, or anything else!
In computer science, variables are containers for information that can change. Variables have a name (e.g., money, health, age) and a value (e.g., $5, 90hp, 11). The value of a variable can change throughout the story, but the name will always stay the same. For example, if the main character in a story bought a banana and ate it, the money variable might go down to $4.69, and the health variable might go up to 95hp.
GPA variableFor the “A Day in the Life” story, the main character’s GPA could change depending on the path the user takes. For example, if the main character skips school, their GPA could go down. If they go to school and work hard, their GPA could go up. Create a GPA variable to track this information throughout the story.
If desired, create a different variable to track a different type of information, like the main character’s
money,HP,stress, or anything else!
<<set $GPA to 2.5>> so the main character begins the story with a GPA of 2.5. Note the syntax:
<< >>)set$)GPA)to2.5)<<set>> line, add the text GPA: $GPA
GPA VariableNow that the main character’s GPA has a starting value, it is possible to update it depending on the story branch.
<<set $GPA to $GPA - 0.2>>
GPA variable to .2 less than it was before<<set $GPA to $GPA + 0.2>>
GPA variable to .2 more than it was beforeEventually, the day in the story will come to an end. When this happens, it would make sense for every story branch to lead to the same place, regardless of how the main character ended up there. At that point, it would also make sense to display the final value for the GPA variable.
[[Night falls]]GPA
GPA: $GPATry to continue the story with some new branches! Write it out on paper or in Notepad first to get an idea of where the story should go. Then, try to update the code to make it into a playable game! Feel free to elaborate on the existing story, or change it completely. Have fun!