Skip to content

Converting Text Variables to Number Variables – The Articulate Storyline Way

Many times, like me, you might have defined variables as strings or Text variables as we call them in Articulate Storyline. These variables, though defined as “Text” may contain numeric values too. This makes it easier to enter numeric values inside a “Text” field and use it for comparisons.

Number variables allow very few comparison operators whereas text variables include a lot of comparison operators. Also, assigning default number types might result in unnecessary decimal points. Therefore, populating a “Text” variable with a numeric value and using it after conversion will help you use a lot of operators easily, when needed.

For a recent project, I had to convert text variables to number variables. I’ll share how I overcame this issue following a few simple steps.

Step 1: Create Variables

In this step, we have to create variables using the default feature of Storyline. There are three types of variables in Storyline:

  • Boolean
  • Text
  • Number

Create variables Step1

For this scenario, we have to create one Text and one Number variable. As shown in the screenshots below, select the variable type by clicking the Type dropdown list. Populating the values of these variables through the data entry box is optional.

Text variable

Number variable

Step 2:Add Triggers

In this step, you have to add a trigger called Execute JavaScript. It’s a default trigger in Articulate Storyline. By selecting the “Timeline starts” option, you can ensure that the JavaScript you write (shown in the next step) will be executed when the slide timeline starts. 

Add triggers

Clicking the Script box opens a new window where you can write the JavaScript.

Step 3: Add the Script

Input the JavaScript code in the window; this will convert your text variable to a number variable.

var player = GetPlayer();

vartextvariable = player.GetVar(“textvariable”);

textvariable = (textvariable * 1.00052658);

numbervariable = textvariable;

player.SetVar(“numbervariable”, numbervariable); 

Add the variable

Step 4: Reference the Variable

Now we have to address the converted variable, i.e., the number variable. For that, you can go to “Insert”, click the “Reference” button and select the number variable.

Reference the variable

The value stored in the text variable will be shown through the number variable.

I hope this blog helps you accomplish this task easily and swiftly.

Please share your thoughts.

Authoring Tool Finder - Find the Best Suited Authoring Tool for Your Needs