Two weeks ago, you learned how to start building your own game with Twine. You started writing the adventure of a princess stuck in a tall tower with a dragon. You learned how to create story nodes and transitions in the story as well as adding images.
I have recently watched Anita Sarkeesian’s Damsel in Distress trope reversal video. Damsel in Distress trope is an idea used in a lot of classic video games, such as Mario Brothers, in which a woman is captured and has to be rescued by a straight male protagonist. At the end of the reversal video, Anita describes a story where a princess rescues herself and starts living a life of general badassery. This stroke a chord with me, since we are developing a very similar game idea. Go ahead and watch the video below and get inspired 🙂
Inspired to continue making your own video game? Good! Let’s continue where we stopped last time! So far we have a beginning of the story, that should look something like this when Test Played (use the menu Build -> Test Play):
If you played video games like Sims, Dragon Age or Mass Effect, you know that those games let you name the characters you create. Let’s add the same functionality to our game!
Rename your “Start” node to “Princess”, like so:
What is the name of the princess? <<textinput $name [[Save|Princess]]>>
If you Test Play now you will see that the code above is rendered as a prompt with text area where you can enter new text and a Save button. The code above creates a textinput, saves whatever has been entered into a variable $name and transitions to the Princess node.
I like to think of a variable as a sticky note. Imagine you are talking to someone on the phone that you do not know. At the beginning of the conversation, you jot their name down on a sticky note so that by the end of the conversation, when you have already forgotten their name, you look back on your sticky note and say “Thank you for your help, <the name from the sticky note>”. Variables in Twine use the same idea. Now let’s Test Play your game. You will see the prompt, the text area and the save button. There is no mention of the $name variable anywhere because it is saved behind the scenes.
Your Twine game board should look something like this now:
Even though we are prompting for and saving the princess’s name, we are not using it anywhere in the text. Let’s change that. Go to your Princess node and add the code that will replace the name variable, by the name you entered, as shown in the graphic below.
If you Test Play your game now, and enter a name for a princess, it will be inserted into the story.
Awesomeness! We have learned how to use variables to save and display the name of your princess character. In the next tutorials, I will show you how to use variables for tracking princess’s health as well as having interesting conversations with the dragon. Have a good week, and CodeBrave!