Forum Discussion
JavaScript in Storyline and RISE
Nick, there are three basic functions used to have Storyline and JavaScript communicate back and forth:
var player = GetPlayer(); ... opens communication between JavaScript and an instance of Storyline. You can change "player" after "var" to any variable name you would like to use (e.g., "var storyline" or whatever). However, you cannot change "Player" in "GetPlayer()". "Player" just refers to an instance of a published Storyline project. You must include the GetPlayer() function before you use GetVar() or SetVar() described below.
var name = player.GetVar("SL_Variable_Name"); ... directs JavaScript to get the value of whatever is stored in the custom Storyline variable called "SL_Variable_Name". Replace "SL_Variable_Name" with whatever your Storyline variable is called (notice the variable name must be placed in double quotes). "var name" is creating a custom JavaScript variable (not a Storyline variable) to store the value of the SL_Variable_Name in JavaScript. Replace "name" with whatever you want to call your JavaScript variable. Note the "player." before "GetVar". If you change the variable "player" above, be sure to change every occurrence of it in your JavaScript.
player.SetVar("SL_Variable_Name", name); ... directs JavaScript to send whatever is in your JavaScript variable, name, to your custom Storyline variable, SL_Variable_Name (again, I'm just using the variables "name" and "SL_Variable_Name" as examples). Notice that the Storyline variable is in double quotes but the variable containing the value you're sending to Storyline is not in quotes. Also notice again that "player." precedes SetVar.
Some additional explanation and sample code can be viewed at this link:
If you would like to describe what you're trying to do and post the JavaScript you're using in one of your Execute JavaScript triggers that isn't working, we can take a look.
- NickRLeVan3 years agoCommunity Member
Steve:
Thank you for your response, this helps quite a bit. We have tabled the ongoing project and the code feels a bit scattered (due to trying all sorts of things at this point) but I can see if posting the code would be helpful.
Ultimately what we were trying to do was have a guide character selection be displayed across RISE sections utilizing Storyline. We were unable to recognize how to store a character selection but we have seen examples of it being done so it is possible.
Update:
here's coding we were trying in order to store a simple name variable. we didn't quite get close enough on storing a guide character selection (we are unsure how that is executed: states? individual images? how does JS know to read an image selection or state selection?)...
Anyway, here's some code we tried. Notice that we tried to utilize local storage so when learners take the course via a web browser they could have their choices stored locally
var player = GetPlayer();
localStorage.setItem("Name", player.GetVar("TextEntry"));this was my first line of code. for the page of entering your name
var player = GetPlayer();
var Name = window.localStorage.getItem('userName');
player.SetVar("TextPull", Name);last JS code
- AmandaJansen3 years agoCommunity Member
Thanks for the Awesome information!