Sum of five numeric learner inputs

Apr 13, 2017

I have five numeric data entry fields on a slide.

Learners can type numbers into any of the five in any order.

The sum total of the five must be displayed anytime any data entry field is revised.

This seems to be a major undertaking in Storyline unless I am missing something.

Sam

12 Replies
Phil Mayor

You can only do the calculation when a control loses focus.

You can set up a listener for when a variable changes and then show a calculation layer which has your (A+B+C+D+E=F) calculation on it.

This way you only need 5 triggers on the base layer checking if the variable changes and they all use the same calculation layer. Ensure you set this to hide when the calculation is complete.

The only sticking block is that the control needs to lose focus to run the calculation.

Sam Carter

The defaults of "0" for inputs is a lie! (grin) 

Setting the variables to zero solves the NaN problem and creates another by firing the "show the layer trigger" before all the variables are set. The total comes up as NaN until the learner enters something and the layer re-fires adding up the zeros and the learner's input.

I will play around moving the triggers in the base layer to see if this fixes the initialization.

 

Sam Carter

So... the cleanest but very tedious method is to set the sum to zero on layer timeline start. (I lied about the slide having five inputs. There are 20 on this slide.)

Add each input field to the sum on the condition that the variable not equal to zero. Apparently this is sufficient to determine that the field is populated.

A significant improvement for SL:  If nothing is entered in the input field, zero would be a good value to be used in calculations. It's a shame (or at least a burden) that it results in NaN.

Sam

Walt Hamilton

I will watch closely. I want to see if this works: "Add each input field to the sum on the condition that the variable not equal to zero."  I am afraid that NaN may show up as not = 0. In that case you should probably set each variable to 0 if it is not > 0 or not = NaN, depending on what the variable actually contains and how it is parsed.

Sam Carter

The calculation is working for me using the condition "not equal" to zero. I guess NaN is not zero.

There are things SL could do to improve this experience.  If there is going to be an "undefined" value for input fields, it should show up as undefined, not 0, in the variables dialog box.

Another help for an input variable with an "undefined" value (so the field appears empty) allow the variable definition to specify a configurable value if used in a trigger calculation.

This begs another question: how to test text input fields for an undefined value. I haven't tested this myself. The other possibility for text input is the empty string which is a defined value.

Sam

Phil Mayor

It is easy to check text entry for blank (undefined) just don't add anything to the condition.

I am sure that there is a bug somewhere here because the value should be 0.

Personally my best and favourite feature would be for the variable to update as it is typed rather than when the control loses focus, I have read that in HTML5 this already happens.

This discussion is closed. You can start a new discussion or contact Articulate Support.