Learning Ink: Part 7: Global, Temporary, and Constant Variables

InkLogo

 

Learning Ink

 

Ink is a scripting language for creating interactive fiction like choose-you-own-adventures and other vast, branching stories.


 

Global Variables

Like many other scripting languages, Ink also understands scope. When created, the type of scope for a variables is defined in how it is created.

Global variables are defined using the keyword “VAR”. They can be used, updated, and accessed across the entire flow. They can contain numbers, strings, and even diverts.

1_VAR

Similar to other entities like a knot or stitch, the value of a variable can be shown using curly brackets, {}.

2_Curly

When using curly brackets and a defined, global variables, its value can be shown in multiple places.

VAR

 

Temporary Variables

When a global might be too much, or a number of calculations need to be carried out through creating new values per step, temporary variables can be used.

Temporary variables are created through using the tilde and the keyword “temp”. Once created, they last during the life of the knot or stitch in which they were created.

3_Temporary

Like other variables, they can also be used as part of conditional statements, checking, like with knots, if their values meet certain criteria.

VAR

 

Constant Variables

Like global variables, constants are set and can be accessed throughout a flow. However, unlike global variables, they cannot be changed once set. Their values are constant.

Constants are created using the keyword “CONST”.

4_CONST

Like other variables, their values can be shown through using curly brackets.

5_Full

Through combining types of variables and considering their scope, flows can be shaped in dynamic ways.

CONST

 

GitHub Gist Version:

CONST name = "Dan"
~ temp fretCount = 0
It was {~Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday}.
I was unsure about asking him out on a date.
CHAPTER 1: ASKING HIM OUT
-> Chapter_1
=== Chapter_1 ===
{&What should I do? | What if I didn't say anything? | Should I ask him out?}
+ [Did he even like guys?]
~ fretCount++
-> Chapter_1
* I should just do it!
I let it go for weeks.
{fretCount > 2: After thinking about it multiple times, I finally asked him out.}
{fretCount < 2: Finally, I asked him out. }
– CHAPTER 2: GETTING READY
Why hadn't I thought about what I was going to wear?
Here I am, 30 minutes before the date and I haven't picked out my clothes!
* (Look_Good) [Pick out something good.] I took some time and picked out something good.
* (Random_Clothes) [Don't bother.] I just grabbed some clothes off the floor and ran out.
– Finally, I was ready.
CHAPTER 3: EATING DINNER
{Look_Good: "You look good, {name}!"}
{Random_Clothes: "Ready?"}
But I hadn't made dinner plans! And they we were, standing outside his apartment.
He turned to me. "What should we eat, {name}?"
-> Pizza_Choices
=== Pizza_Choices ===
* [Pizza?] He shook his head. "I don't like pizza."
-> Pizza_Choices
* [Salad?] "Not a salad."
-> Pizza_Choices
+ [Nothing?] {"We have to eat something!"|"Stop being silly, {name}!"}
-> Pizza_Choices
* [Sushi?] "Sushi sounds good!"
We walked to the local sushi place.
-> END

view raw
ChoicesAndKnots.ink
hosted with ❤ by GitHub