(Twine) Logic Adventure

Take your players on an interactive journey with variables and logic

Students per team : 1

Estimated Time Investment : 90 minutes

While intimidating, variables can be thought of very simply– a variable let’s the computer “remember something”, such as the player’s health, time remaining, etc. We may then change the game based on the values of these things (is the player “health” variable below 0? End the game).

Purpose

Logic Adventure tasks students with using variables, logic, and input boxes to make an extra-interactive game.

Background Info

The following tips will help you complete your Logic Adventure quickly.

Case Study : Logic Adventure

Variables

Open the “Logic Adventure” twine story you downloaded above.

Open the “Start” passage, and you should see something interesting–

From previous tutorials, you should recognize the branch at the bottom, and the header line in the middle, but what is up there at the top?

These lines are special “command” lines, denoted as such by the “«” carrots that begin the line and the “»” carrots that end it. If you consider the lines one at a time, things get easier–

Between the carrots, this line can be broken into four pieces (or “tokens” in Computer Science terminology). The tokens are “set”, “$required_money”, “to”, and “7.00”–

  • “set” : This is the command name, and tells us what this command will be doing, and also what kind of “parameter” tokens must follow this one. This is the “set” command, so it allows us to “set” a variable (AKA, store something), but what variable are we going to use, and what are we going to put inside it?
  • “$required_money” : This tells Twine what variable we want to use in this “set” command. As far as the game itself is concerned, the “$required_money” variable is the amount of money the player needs to find to win. Note how the variable name has a dollar sign at the front of it– all variables in Twine begin with a dollar sign in their name (this is how we know they are variables instead of something else).
  • “to” : This is just a little connector token used with the “set” command.
  • “7.00” : This is the value we want to place inside the “$required_money” variable. In other words, at the beginning of the game, the player only needs 7.00 dollars to win.

Instead of showing text to the player, this line causes a “set” command to be run, and this command places the number 7.00 into the variable $required_money. Because variables can change during gameplay, it’s a great way for us to store things that can change (such as the amount of money required to win, the amount of money the player currently has, the player’s energy level, etc).

Take another look at the 7 “set” commands that begin the game–

Can you tell what each one is doing? Ask yourself this– can we store OTHER things besides numbers inside a variable?

The StoryCaption panel (left panel)

When you have a variable, sometime we want the player to be able to see what it is!

  • If you’re making a game in which the player has “health”, players will be frustrated if they don’t know what that value is. Make it easy to check!

How can we allow the player to see the value of a variable while the play the game? If we were testing our commands and logic, how could we know ourselves as developers?

Enter the “StoryCaption” passage–

The StoryCaption passage is special. If you give a passage the name “StoryCaption”, twine will place its contents into the sidebar on the left of the gameplay screen, like so–

When playing the “Logic Adventure” game the instructors made, this is where they chose to place important variables like the player’s name, their energy, their money, etc (but not the required money, hee hee…).

Open up the StoryCaption passage, and you’ll see this–

Whenever you see a variable (with dollar-sign), this means that, instead of writing the actual text “$player_name”, we’ll instead get the VALUE of that variable (AKA, whatever is inside it).

The following lines are bits of logic– we’re using them here to hide certain things in the inventory.

Let’s find out how they work!

Logic

Find the “Search the nearby rocks” passage.

Look through the passage and notice two commands (and a third of which is the kind of “set” command you’ve seen earlier.

In this passage we have an “if” command–

And an “endif” command two lines below it–

These two commands work in tandem. If the “if” command evaluates to true, every line in between this “if” command and the next “endif” command will execute, otherwise nothing in this block will.

In this particular example, we want to tell the player that they “cannot carry any more rocks” if they already have some rocks in their inventory, so we check the variable (if it’s true, we have rocks), and display a message if necessary.

Input Field

Sometimes we would like the user to provide some information. In the “Logic Adventure” game, for instance, players are prompted to provide their name–

Locate and open the “Listen, my wallet is empty…” passage–

Player input boxes are created via the “textbox” command, which you may learn about here.

The “textbox” command also requires the player to specify–

  • A variable name (“$player_name”) for the player’s message to get placed into.
  • A default value (“Truly Tired Person”) that begins in the textbox.
  • A passage name to jump to after the player enters their message (“primary_qa”).
  • The “autofocus” token at the end of the command can be omitted, but causes the textbox to be auto-focused when the player arrives at this passage.

After the player enters their name, this value goes into the “$player_name” variable, which is what is shown at the top of the StoryCaption pane (left side of the screen near inventory).

Tasks

[ ] Create your own “Logic Adventure” game that has at least 10 passages… [ ] At least 5 variables in-use… [ ] At least 2 pairs of “if” and “endif” commands… [ ] At least 1 textbox…

[ ] Publish your game!

  • Submit your assignment by creating a new game on itch.io (follow the directions under “Distribute Your Game” on this page).
  • Once the game is working on itch.io, send your game to at least one friend or family member for playtesting!

Updated: