you can do the same thing with triggers, using whatever action you are using to initiate the javascript.
Adjust variable Sum = 0 when user clicks button
Adjust variable Sum ADD Variable 1 when user clicks button
Adjust variable Sum ADD Variable 2 when user clicks button
Adjust variable Sum ADD Variable 3 when user clicks button, etc.
You just need a trigger for each step (6 triggers) that all fire from the same user action.
The advantage of using triggers is that it is easier for someone who doesn't write JS to do maintenance on the module. Also, triggers function in preview mode, while your module must be published for JS to function.
Unless there is another reason you want to do this in Javascript, I suggest it would be better to use Walt's method above. Javascript is very powerful, and can let you do a lot of cool stuff. But, it can be difficult to troubleshoot, and will not run in the preview mode. I only add javascript to my projects when I can't figure out any way to do it in Storyline alone.
I just wanted to note, for anyone who might be diving into JavaScript in Storyline, that Dave Cox's solution, at the top of this thread, works just fine here in 2022 with the latest version of Storyline 360 (v3.61.27106.0). Thanks, Dave, for the help. You steered me in the right direction.
(Now that I've made it work in JS, I'm going to try making it work using Walt's trigger-based solution.)
9 Replies
Hi Fatma,
This will do it.
var player = GetPlayer();
var sum = player.GetVar("Variable1") + player.GetVar("Variable2") +
player.GetVar("Variable3");
player.SetVar("Sum", sum);
Replace Variable1, Variable2, Variable3 and Sum with your own variable names in Storyline. I only did three, but you can add as many as you want.
Thank you for your help Mr Dave Cox. :)
FYI:
you can do the same thing with triggers, using whatever action you are using to initiate the javascript.
Adjust variable Sum = 0 when user clicks button
Adjust variable Sum ADD Variable 1 when user clicks button
Adjust variable Sum ADD Variable 2 when user clicks button
Adjust variable Sum ADD Variable 3 when user clicks button, etc.
You just need a trigger for each step (6 triggers) that all fire from the same user action.
The advantage of using triggers is that it is easier for someone who doesn't write JS to do maintenance on the module. Also, triggers function in preview mode, while your module must be published for JS to function.
If you need more help Ashley Chiasson just made this tutorial this week on adding variables with triggers. It's a nice little video. http://ashleychiasson.com/blog/screencast-adding-values-using-variables-in-articulate-storyline/
Hi Fatma,
Unless there is another reason you want to do this in Javascript, I suggest it would be better to use Walt's method above. Javascript is very powerful, and can let you do a lot of cool stuff. But, it can be difficult to troubleshoot, and will not run in the preview mode. I only add javascript to my projects when I can't figure out any way to do it in Storyline alone.
Thanks for helping Mr/ Walt Hamilton, this is a piece of cake, and i will use it.
You are right MR/ Dave Cox, thanks :)
Thank you so much MR/Richard Hill. :)
I just wanted to note, for anyone who might be diving into JavaScript in Storyline, that Dave Cox's solution, at the top of this thread, works just fine here in 2022 with the latest version of Storyline 360 (v3.61.27106.0). Thanks, Dave, for the help. You steered me in the right direction.
(Now that I've made it work in JS, I'm going to try making it work using Walt's trigger-based solution.)