Forum Discussion
How to remove an initial value (0) from a "Numeric Entry" field
I have created a (rather complex) work-around, which I think works really well.
Try it out here:
http://elearning.hosp.dk/0Afproevning/SNORRESLEGEPLAD/story_html5.html
I have also attached the story file if you want to copy it.
Instead of actual numeric entry fields, it uses javascript triggered by keypress, and a couple of variables.
Numerical: "currentValue"
Text: "currentValueText"
If you have more than one input field: "currentVar"
The text variables seen in the slide: "a", "b", ...
If there are more than one "field" I use layers for each.
In this case, layer "a" opens when timeline starts, and sets "currentVar" to "a". I use that variable to tell the storyline which variable needs to be updated.
Now in a master template, I have made a number of keystroke triggers, with a javascript function in each. E.g. if you press "1" this scripts is triggered:
var player = GetPlayer();
var val = player.GetVar("currentValue");
val = player.GetVar("currentValueText");
val = val*10+1;
player.SetVar("currentValueText", val);
player.SetVar("currentValue", val);
This will add a "1" to the number in both the "currentValue" number variable, and the "currentValueText" text variable. The same happens if you press "NUM1". For each of the other number and numerical keyboad keys, a similar script is triggered, just with "val*10+2", "val*10+3", etc.
Now if you press "DEL" another script is triggered:
var player = GetPlayer();
var num= player.GetVar("currentValue");
var div= "10";
var dec= num / div;
var res= parseInt(dec);
player.SetVar("currentValue", res);
if (res == 0) {
res = "";
};
player.SetVar("currentValueText", res);
console.log("dec: " + dec);
console.log("res: " + res);
Which shaves the last digit off the number.