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.
I tried this and found I got NaN... I deduced this as a result that the inputs not yet filled in by the learner actually do not have the default value of zero as shown in the variables dialog box.
I will try initializing all the inputs to zero to see if this resolves the issue.
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.
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.
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.
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.
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.
12 Replies
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.
Hi Phil,
I tried this and found I got NaN... I deduced this as a result that the inputs not yet filled in by the learner actually do not have the default value of zero as shown in the variables dialog box.
I will try initializing all the inputs to zero to see if this resolves the issue.
Sam
Odd that you get NaN may be a bug in there.
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.
can you set them to 0 before they get to that slide?
Or set them to 0 on the calculation layer if they are not > 0 ?
That would work
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
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.
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
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.
Either that or I would like a trigger for when control changes :-)
This discussion is closed. You can start a new discussion or contact Articulate Support.