Forum Discussion
Keypad Input simulation - 8th digit glitch
Hi boffins. It's me again hoping for some assistance.
I have a project that simulates a user interface whereby the user is asked to enter numerical data a few times. I have discovered it is... hard to do - or else my brain has turned to mush in the 2 weeks since I have had COVID, but I cannot get any methodology to work for me.
I did a search of the boards here and found Phil Mayor's delicious Sweet Shop module and it is EXACTLY what I am hoping to achieve.
After TONS of messing around with variables, I established a very clean set of triggers which simply multiply whatever the previous value is by 10 and then simply add the new keypad input value to that total.
Here is my demo:
This works fine for the first 7 digits of the sequence, but it just goes weirdly random (or at least I cannot discern the pattern) on the 8th key press. It simply starts adding zeros no matter what key is being pressed.
Is there a limit to the value Storyline 'calculates' values?
Is there an easy way of simply getting a user to type in a numeric string, such as an ID number, or telephone number without all this... ugh... mathematics... <shiver>?
Can anyone discern where I have gone wrong? Or provide an alternative solution that doesn't melt my poor COVID-addled brain?
- DiarmaidCollinsCommunity Member
Managed to figure something out on my own. Yay me! Not as elegant as the solution above that, by rights should work with no issue, maths being maths 'n' all, but at least this gets the job done.
In a very heavy-handed manner, by breaking the desired 8-digit string into individual number variables. Ugh.
Surely inputting number strings should be easier than this? I know I must be missing something truly basic to have had to go through all this... thinking... (my head hurts).
Here's the working "solution" and below is the link to the file if anyone wants to take it apart, use it, or suggest better alternatives.
- DiarmaidCollinsCommunity Member
Hi Cassie. Very late in responding to your kind words. I hope it worked perfectly for your project.
I know this is a long shot but I don't suppose you figured out the failure of logic in the first post (file)?
I haven't solved it myself and was hoping some math guru could explain where it goes wrong in the file.
Anyway, no worries. Glad you liked the demo.
- Nathan_HilliardCommunity Member
That actually appears to be a bug in how Storyline is adding to values over 7 digits. With multiplication alone, the number can extend to 17 digits. If you add anything to a number over 7 digits however, even adding 0, the number gets truncated and just increases by a factor of 10. Probably some kind of rounding error in the internal math. I'm kind of suprised that this would still exist after this long.
I tried some variations on the calculation, but they all ended up with the same result. The fix for this would be to use a JavaScript trigger to add the values. Create another numeric variable called keypress. Use it to hold the key value clicked by the user (0 to 10). Then, create one more true/false variable called triggerAdd.
Now instead of using the multiply by 10 and add 1 triggers for each key click, add the following JavaScript triggers for each:
Finally, create the following Execute JavaScript trigger:
Using this code:
let kp = Number(GetPlayer().GetVar("keypress")); let val = Number(GetPlayer().GetVar("INPUT_DRIVER_ID")); val = val * 10 + kp; GetPlayer().SetVar("INPUT_DRIVER_ID", val);
The remaining triggers should be OK.
Demo: https://360.articulate.com/review/content/f6491348-9628-410c-aad9-5286ea856bce/review
- Cassie_EricssonCommunity Member
Hi Diarmaid! I ended up using JavaScript to create my numeric keypad interaction. It was helpful to see how other people approached it, and that led me to trying a few things (including my JavaScript solution!). I'll add a demo Storyline file here so you can check it out!
- Cassie_EricssonCommunity Member
Thank you so much for posting this! I need to create a module with a working number pad and this was really helpful!