Storyline variable data type bug
Hello e-Learning Hero community!
I have been very disappointed with Storyline recently, and need some help understanding it’s absolute INCONSISTENCY when it comes to handling the data type of its variables.
As this issue involves JavaScript, so naturally I don’t expect any help from the Articulate – so I’m asking for some help from the community. Even though there is JavaScript involved, I have narrowed down the bug to being caused by Storyline. (as far as I can tell)
This is attached to a larger project which I cannot share, but have been able to replicate what is happening with this proof of concept: https://360.articulate.com/review/content/8d644591-11c6-47c4-af71-e4b495e6390f/review
In Storyline, I have 4 numeric variables: number1, number2, number3, Sum.
Before the slide in question, I have 3 storyline triggers that set the value of number1, number2, number3 to specific values. Let’s say they get set to 25, 45 and 65.
When the slide starts, I run an execute JavaScript function to add those 3 together and push value to the variable Sum.
Here is the JavaScript.
var player = GetPlayer();
var value1 = player.GetVar('number1');
var value2 = player.GetVar('number2');
var value3 = player.GetVar('number3');
var sum1 = (value1 + value2 + value3);
console.log('Sum', typeof sum1, sum1);
player.SetVar('Sum',sum1);
Everything up to this point works as expected. When automatically ran at the beginning of the slide, the sum correctly gets set to 135 and the log in the console shows Sum remains a number.
Now onto the bug.
On the following slide, I have 3 numeric entry fields that are linked to the number variables I mentioned above.
Numeric Entry Field 1 is assigned to the variable “number1”
Numeric Entry Field 2 is assigned to the variable “number2”
Numeric Entry Field 3 is assigned to the variable “number3”
If you change ANY value amongst the 3 numeric entry fields and click “Calculate” you will see the Sum update and push a new log to the console.
Let’s say we change the 3 values to 32, 51, and 66 respectively.
Instead of the sum being 149 like it should, you’ll notice that it instead becomes 325166. You can check the type of each of these variables in the log and you will see that ANY value we change becomes a String. This causes our numbers to concatenate instead of add together.
While I could absolutely implement code to automatically filter these values into numbers, that is not a sustainable solution.
I’m trying to understand better WHY this is happening and if there is a workaround that’s actually sustainable and doesn’t create extra work for me.