Variables and Conditions

profilemaole525
CAS208-Exercise2.pptx

Exercise 3

Variables

This week, I want you to add conditions and items to your storyworld using variables, macros and conditions.

Create a story with three variables and three condition states with your story.

Goals

Creating Variables

By placing text in () ellipses in Twine, we tell twine that these aren’t words to display, but actions to run.

Twine uses the $ dollar sign to indicate that this is a variable.

Using set: we can tell Twine what value, number, or words to put into the variable

If I wanted to create a variable named $coins to keep track of how many coins my player has and give it a value of 100, I would write the following:

(set: $coins to 100)

If I wanted to keep track of whether or not I have a key, I would use “true” or “false” in a variable named $key:

(set: $key to “true”)

Creating Variables, continued

A couple of important notes about variables in Twine:

The value for any particular variable can be anything you want. It can be a number (0, 1, 2, 3, etc.) or a word (“true”, “false”, “pig”, “cow”, “xbox”, “bike”, etc.)

But I need to use “ ” quotations for words.

Whenever you properly set a variable, the whole line will change color (see image to right)

If you finish setting a variable and it does not change color, then something is missing

Using Variables

You can use variables to either display information about the story state or store information about the story. You use the same () notation as the passage text. Let’s say we are keeping track of our player’s health:

Health: $health

You can also use conditions to change the story content. On the right you can see how one would lay out the use of variables for a Twine story.

What is a Condition?

A "condition" means create a situation where something the player does affects the story in a meaningful fashion. Examples:

A door that won't open unless the reader has a key.

Conditions: Either have key, or don’t have key.

If you smash the pot, it stays smashed if you come back to the room.

Conditions: Pot is either smashed, or not smashed.

These examples might seem overly simplistic but keep in mind that computers only know what we tell them.

Conditions are coded using "If" statements, using the (if: ...) format. You begin with an (if CONDITION). The condition portion can be either a simple “equals” statement or use “greater than” or “less than” signs for numbers. Any action that takes place in between the [] square brackets after the condition will be run if the condition is true.

(if: $potSmashed is true)

[

The pot is in a thousand pieces.

]

Using Conditions

When you create the conditions, please consider the following:

Conditions should change the player's experience based on their choices.

Each condition needs to have at least two sides:

What happens if you have the key?

What happens if you don’t have the key?

Most importantly: the conditions should add meaning to the experience.

Here are a few common pitfalls to avoid:

Conditions must be coded To count as a condition for this assignment, the passage must use an (if:…) code and change the experience based on a variable's value.

Variables need to change. A variable's value must be changed as the result of the player's action. Otherwise, any conditions are meaningless.

Conditions should be meaningful. Related to the previous point, make sure that your conditions make a difference in the experience. It doesn't make sense to offer the player a choice of red or blue pill and then present the exact same outcome.

Conditions, and variables can be intimidating, but they’re really not that bad. Think about the following scenario: If it rains out tomorrow, I will bring my umbrella.

(if: $weather is “rain”)[

I will bring my umbrella.

(set: $item to “umbrella”)

]

Conditions and Variables

We think and make decisions in real life all the time, right? We just don’t normally think of them as “if” statements, and we don’t think of our wallets and keys and umbrellas as variables.

Writing it Up

See D2L and http://twinery.org/wiki/ for more examples and resources!

Create a story with three variables and three condition states with your story. The variables and conditions don't necessarily need to line up (e.g. one condition could use two variables at once or one variable can be used in two different conditions).

Yes! It's okay to change your story plan or story content. Part of developing interactive content is revising and iterating.

Create a short document that itemizes your three variables and conditions

This is so don't miss some of your hard work and mark you down. The variable portion of this doc can be as simple as this:

Variables:

$hasKey - whether or not you have a key

$health - how much health you have!

$gold - how much gold you have.

Hand in the document and the story's index.htm in a zip file to the D2L dropbox.

Grading

25% Conditions: 3 functioning conditions (e.g. the user can't open the door unless they have a key).

25% Variables: 3 variables (does the player have key? what is the current time? etc.)

25% Interactivity: No bugs or issues that would interfere with the user experience.

25% Creativity: Are the interactions interesting, relevant, and meaningful to the experience?