SmartBuilder > Help Documentation > Actions

Using Variables

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:

Set Variable to Next from Input Text 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).

Set text to Appended Variable

Create a variable

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.

Set Global Variable to 0

By default, each lesson contains two variables "Variable1" and "List1"

Two Default Variables

You can rename these default variables, or create new variables. For example, to create a new variable called "Count":

  1. From the set variable block, click on the variable dropdown and select Create New Variable.
    Create New Variable
  2. Type a name for the variable and click Create.
    New Variable Name
  3. The set block will be using the new variable.
    Set New Variable to 0

Set a variable

You can set a variable to specific value. For example:

Set Variable to 15

Or, you can modify a variable using add, subtract, append or set. For example, this will add 1 to the value of Count.

Add 1 to a variable

Get a variable

Use the get variable block to retrieve the value of a variable. For example, to make the Text 1 object display the Count variable:

  1. Add a Set Text to Text Block to block to your canvas.
  2. From the Variable action category, select the get variable block.
    Variable Actions: Get Variable
  3. Snap the get variable block into your statement.
    Set Text Object's text to Variable
  4. Click on the variable dropdown and choose the desired variable
    Select your new Varibale
    Select your new Varibale

Debugging variables

The debug feature is a powerful way to quickly analyze how variables are changing at runtime.

preview debug button

Display a variable in text

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 "name", then "Hello {{name}}, in this exercise..." would become something like "Hello Bianca, in this exercise…"

curly brackets to show variable in rich text