working with javascript
By
suma lama
hi,
I tried to the following code but it does not work, why?
var player = GetPlayer();
var a = player.GetVar("x");
var b = player.GetVar("y");
var sum;
sum = a+ b;
player.SetVar("s", "sum");
where, x,y and s are variable i created in storyline.
can anybody help?
thanks!
5 Replies
Hi, Suma -- Thanks for your question and welcome to the community! Unfortunately, I am not equipped to provide support on JavaScript coding, however, I did want to provide this information on JS Best Practices so you have it handy. I know we have lots of JS gurus in the community, so hopefully, someone will be able to chime in to assist you further! :)
Hi Suma!
I think it works if you'll write the last line:
player.SetVar ("s", sum);
In your code the variable "s" gets the value "sum" !
I agree with Sebastian. Also, I don't quite see the need to use JS to add two Storyline variables and store the result in a third SL variable. You can do that with triggers.
Sebastian, thanks it works.
Micheal, could you elaborate more
thanks!
So glad to hear Sebastian's suggestion did the trick for you, Suma! Thanks for the update. :)