Number Variables Error: NaN

Feb 26, 2022

Hi Everyone,

I'm working with number variables to create a budget calculator. Where the multiple sources of income (variables) are added when the learn taps calculate. It was working perfectly and this morning when testing I receive the following error: NaN.

Also, when adding the numbers do I need to do anything different when entering dollar amounts (0.00)? Any help is appreciated. 

Thank you!

Adriana

8 Replies
Math Notermans

NaN normally means a value 'is Not a Number'.
However when checking your file, all variables used are numbers.

As Articulate recently changed how referencing variables works, i suppose this is a bug in Storyline. Im going to do some more digging...seeing if i can find a workaround...but do think this is a bug.

Walt Hamilton

It is a bug, but it is worse than just a simple bug, it is a horrible betrayal. People have been asking for the ability to put 0 into text entry boxes as a default value. Kudos to Articulate, they finally fixed that. But in the process, they have done two worse things. You had five variables, with similar names, distinguished by a trailing number (NumericEntry1, NumericEntry2, etc.). That made it very easy to use them as references. You could use the menu to insert the reference, or you could type %NumericEntry1%. Then it was easy to edit it to show a different variable, by simply changing the number. Or, if you needed to see them all, you could duplicate the first one, and just change the number for the duplicates. Intuitive, and easy work flow. With the new "improvement", we have lost that ability. You can type the name of the reference, as before, but it changes to a single unit, meaning we cannot edit it. Now each change must involve the much slower method of going through menu tab.

The other problem (which admittedly could have been with us from the beginning), is that the default value is mis-programmed. It is slightly possible that it could be showing as a null, but I think it much more likely that it is showing as a text character. So when you put a default value of 0 in a variable, don't change it, and attempt to perform a calculation with it, SL regards it as a text character, and the result is NaN.

For now, for your purposes, you can change the six triggers attached to the Calculate button to perform their action, adding the condition: If the variable is greater than or equal to 0. That doesn't attempt the calculation unless there is an actual number in the variable, and it works. 

As to your other question concerning dollar amounts, you don't have to do anything different to enter them. To display them correctly is a different matter. SL does not handle that sort of format. What that means is that $1.10 will display as $1.1. The only way to show trailing 0 is to run a js that will format it correctly, and return it to SL as a text, placing it into a text variable.

Maria Costa-Stienstra

Hi, Walt.

Thank you for opening a support case! I see you worked with Ian, who logged this as a possible software bug where a numeric entry field variable not using its default value when the entry field is left unchanged results in a NaN.

We'll come back to update this discussion when we have any news to share.

Diane Peters
Walt Hamilton

For now, for your purposes, you can change the six triggers attached to the Calculate button to perform their action, adding the condition: If the variable is greater than or equal to 0. That doesn't attempt the calculation unless there is an actual number in the variable

I tried this and it still doesn't work. What else have I done wrong?

Walt Hamilton

You have the same problem as Adriana. When you put a default value of 0 in a variable, don't change it, and attempt to perform a calculation with it, SL regards it as a text character, and the result is NaN.

Also, if the learner clicks the Score button halfway through, then again later, it will show twice the actual score. To solve both of those problems, create a trigger to set TOTAL to 0 when user clicks BUTTON_SCORE. then move it to the top of the list of triggers for clicking on BUTTON_SCORE.