Forum Discussion
Javascript division of existing variables
Hi all,
I need some help - I've not written JavaScript before but I think it would be the solution to my problem... I need a new variable (var.c) that returns the value of a division of two existing variables (var.a and var.b): var.c = var.a / var.b
For context, var.a and var.b increase or decrease as the user clicks other buttons and I need var.c to update at the same time without additional steps.
Now, of course, the first solution would simply be to set two triggers (i) for var.c = var.a when something happens, and (ii) to divide var.c by var.b when something happens. The problem here is that I need var.c to recalculate a new result each time either var.a or var.b changes. I tried adding other triggers to solve this by setting var.c = 0 when var.a/b changes however Storyline doesn't seem to allow for a few triggers (set and divide) to happen simultaneously to the same variable (or is there a way?).
The second solution would be to add buttons such as a 'refresh' button and 'calculate' button that when clicked will perform the equation. However, for my solution I need var.c to constantly update and display on the same slide without the user needing to hit additional buttons (the user needs to see how adjusting var.a and var.b impact the result in real time).
Hence, JavaScript.
I need JavaScript to pull the values of var.a and var.b, to divide var.a/var.b and to push the new result into var.c each time that var.a changes (note var.a and var.b both change each time the user interacts with the slide).
I have a few other things to solve, but if I can get this one working I can move to the next issue.
Thanks so much to anyone who can offer advice on this.
Kind regards, Kevin
- MichaelHinzeCommunity Member
Maybe I misunderstand what you are trying to do, but this seems pretty straightforward, no JS needed. See attached a quick example of how this might work.
- KevinMcGrathCommunity Member
This is so brilliantly simple - thank you Michael!