Twine variables

POWER-UPS, COINS, AND OTHER ITEMS

ocarina1Lots of things can be stored as variables. A variable can be something that is typically found in a video game (points, lives, power-ups, coins, items, weapons, health, etc.) or a variable can be something weird (ninjas, cellphone, fire breath, pizza toppings, random treasure, etc.). You can use $icespell to keep track of if the player has learned the ice spell. The number of coins can be remembered with either $coins or $money or $rupees or something like that.

WEAPONS, HEALTH, AND WEIRD THINGS

You can use $lives to store the player’s extra lives and $pizzatoppings to store the number of toppings they have collected. The player’s $health might start at 100, but can change during the game. The player might start without a $weapon, but then find one later. The first thing you need to do is set these things to zero (or to 100 or to whatever number they should start at) in the starting passage.

(set: $money to 0)
(set: $keys to 0)
(set: $sword to 0)
(set: $health to 100)

mariocoinsJust like with the number of keys (which I mentioned in my last post), use set to change things later in the game. The code below says to the computer, “Take the player’s health, subtract ten, and set this as the player’s health.”

You fell down the stairs.
(set: $health to $health – 10)

The code below says, “Take the player’s money, add 25, and set this as the player’s money.”

You found $25.
(set: $money to $money + 25)

WHAT IS YOUR NAME?

fightclub1You can store either words or numbers in a variable, but so far we’ve only been talking about storing numbers. One common word variable is the player’s name. We can use the code prompt to create a popup box in which the player can type their name. The following code shows the player a popup box that says, “What is your name?” and stores what they type as $name.

(set: $name to (prompt:"What is your name?",""))

Once the player’s name is stored, you can use $name to show their name .

Hello $name, how are you today?


mario

CONTINUE TO THE NEXT POST: Twine logic





RECENT POSTS