A variable is a named value that can be changed (varies). For example, you could create a variable called "First_Name" and then set the variable to whatever the learner types into a text input object:
Then, on a later page, you could retrieve the variable and display it back to the learner. For example, when the page loads, Text 1 will display something like "Hello, Name" (where Name is whatever the learner entered earlier).
You may create variables at any time through the "set" block. These are traditionally called "global variables" meaning that they can be set and retrieved from any page in your lesson.
By default, each lesson contains two variables "Variable1" and "List1"
You can rename these default variables, or create new variables. For example, to create a new variable called "Count":
You can set a variable to specific value. For example:
Or, you can modify a variable using add, subtract, append or set. For example, this will add 1 to the value of Count.
Use the get variable block to retrieve the value of a variable. For example, to make the Text 1 object display the Count variable:
The debug feature is a powerful way to quickly analyze how variables are changing at runtime.
For most use cases, you can use the methods above to set or get variable values. This reduces the chance of typos, and makes searching for variables easier.
For advanced use cases, where the specific variable that is being targeted might vary, it is possible to use the set path and get path blocks.
This method also makes some changes to list variables easier:
The primary use case is for getting and setting values with map variables, which previously required many blocks to get or set values.
Setting specific map values can be done in a few different ways:
In very advanced use cases, you can also use the curly bracket notation inside of get/set path blocks or inside text blocks to refer to a variable value.
Or use a join block inside of a get path block to reference a dynamic value.
The easiest way to display a variable is to use the name of the variable inside curly brackets within a text object. For example, if you store the learner’s first name into a variable called "user_name", then "Welcome {{user_name}}, to this lesson..." would become "Welcome Fiona, to this lesson…" once you Preview or Publish the lesson.
If the variable value updates at any point, you do not need to use any actions to update the displayed text, it will automatically update.
This same method can also be used for more complex variable structures, such as lists and maps. For a list, use square brackets to supply the index of the value that you want. For maps, you can access data stored within the structure using dots.
Examples:
Welcome, {{user_name}}, to this lesson!
The third item in fruitList is {{fruitList[3]}}.
On Question 3, you got {{Quizzes_map.Quiz1.pg27.points_earned}} points.