Variables and Conditions

profilemaole525
CAS208-VariablesandConditions1.pptx

Expressions & Variables

CAS 208

Programming

You may not have realized it yet, but you have been programming using Twine for the last several weeks! Quoting wikipedia here:

Computer programming (often shortened to programming) is a process that leads from an original formulation of a computing problem to executable computer programs.

To the right is an image of a flow chart for a piece of software. What you have been doing so far is breaking a story into splitting decision points and telling the computer where to go based on what the use chose.

What is a Variable?

It would be nice though if we could make more complex decisions than just which door a player chooses to go through. This is where Variables come in. A variable is a bit of information that you store about the state of your story. Examples:

How many arrows do you have?

What time is it?

Do you have the golden key?

What is your name?

What is your gender?

While you are likely already familiar with variables in algebra; the video on the right will give you a brief introduction into what variables are in programming.

Using Variables to Tell Stories

On a technical level, variables are just boxes to put things in, but by letting us keep track of things from one passage to another, we can tell more interesting stories.

You have already learned from making branching stories that the more branches you create, the more complicated your story can get. One solution is to simply narrow your branching story to a few possible endings (see right). However, this makes the user feel like they don’t have a choice

Using variables, we can simplify the story path, but still give the player meaningful choices to make. Check out this article on how variables improve the endings of your stories

Locks & Keys

Many games (Legend of Zelda, Gone Home, Tomb Raider, Metroid, Resident Evil, etc.) are boiled down to the same core idea: “Find the right key for this lock”

The lock and key mechanic has long been a mainstay of the adventure game genre. Players are often given several items that seem to serve no purpose only to use them later, often in a clever way, thus unlocking the next part of the adventure. Whether we are talking about hookshots, or crowbars, or superjumps; they are all just keys to unlock a new part of the story.

This article from Gamasutra talks about the use of keys in games, maybe you’ll get some ideas for your story.

A Note on Consistency

The number one reason that students’ Twine projects don’t work is typos. Variables are case sensitive.

Whereas you or I could read “snack” and “Snack” and rightly conclude that they are the same thing, a computer cannot understand.

Computers are very literal, they will do exactly what you ask them to; no more, no less. When they cannot complete your request (say you ask Twine to check for a variable that does not exist) they get confused and throw up errors.