Storing values using VAR
In Chapter 2, Knots, Diverts, and Looping Patterns, variables were introduced as a part of using labeled options within the weaves of looping structures in ink. By creating a label, an option could record whether it had been shown before. This allowed us to keep track of the number of loops within a knot easily. Within ink, labeled options are one form of a more general concept for storing and changing any kind of value. This more general form uses a special keyword: VAR.
The VAR
keyword creates a variable that's capable of storing different types of data. Variables created with the VAR
keyword can store numbers (including decimal values), strings (collections of letters, numbers, and special symbols enclosed in single-quotation or double-quotation marks), Booleans (true
or false
values), and even diverts. Variables created using the VAR
keyword are also global: they can be accessed by any code that is part of the overall project.
Variable names...