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: