9 Replies
Dave Cox

Hi Fatma,

This will do it.

var player = GetPlayer();
var sum = player.GetVar("Variable1") + player.GetVar("Variable2") +
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.

Walt Hamilton


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.


Dave Cox

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.

James Martin

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.)