Is JS API for SL available online?

May 09, 2014

Need link to the JS api for SL.

Thanks!

5 Replies
Steve Flowers

Yep - that's all there is

var player=GetPlayer(); //GetPlayer establishes an object reference to the player

var grabValue=player.GetVar("storylineVariable"); //GetVar retrieves the value of a named variable within the SL player. One parameter.

player.SetVar("storylineVariable",javascriptVariable); //SetVar sets the value of a named variable within the SL player. Two parameters.

David Oskorus

I was trying to grab a value from the SL player for javascript use just now, and was running into some trouble. It worked fine for string variables, but not for numbers.

For example, I had two variables set up in Storyline:
mySLTextVariable = "hello"
mySLNumberVariable = 678

So while this worked:

var player = GetPlayer();
var javascriptTextVariable = player.GetVar("mySLTextVariable");
alert("the storyline text value is: " + javascriptTextVariable);

this did not:

var player = GetPlayer();
var javascriptNumberVariable = player.GetVar("mySLNumberVariable");
alert("the storyline number value is: " + javascriptNumberVariable);

After much head pounding, I finally got it to work by initializing the number variable in the javascript

var player = GetPlayer();
var javascriptNumberVariable = 0;
javascriptNumberVariable = player.GetVar("mySLNumberVariable");
alert("the storyline number value is: " + javascriptNumberVariable);

Just wanted to share in case anyone else was running into the same problem.

This discussion is closed. You can start a new discussion or contact Articulate Support.