JavaScript in Storyline and RISE

Jul 07, 2023

Hello! I have been researching and messing with JavaScript for use within Storyline and RISE for roughly six months, but am still unclear on many details. First off, why is the term "player" used? (i.e.  var player = GetPlayer();)

Why specifically was this term chosen? Or is it an arbitrary term that was selected by Articulate? For me, knowing the 'why' helps me understand issues much better.  

I understand that in order to effectively use JS within Storyline you must have your SL variables set then use JS to retrieve the variables and finally communicate back with SL to display information. Through my Master's program I was able to retrieve some code from a professor but I'm unable to 'break through' on this as of yet. 

The ultimate goal is to figure out JS within Storyline, and then to be able to use SL (utilizing JS) within RISE in order to create RISE courses with all of the personalized functionality from SL but housed within a sleeker, more fluid course structure. (ergo: being able to enter your name, choose a guide character, etc., and have RISE communicate with SL blocks to display information during a RISE course.

We have been unable to figure this out utilizing local storage, etc., and my thoughts are that the coding is simply not correct. However, I feel that we are close.

If there is anyone who can assist with this it would be much appreciated.

6 Replies
Steve Gannon

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:

https://articulate.com/support/article/Articulate-Storyline-360-JavaScript-Best-Practices-and-Examples 

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.

Nick LeVan

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

Johan Schoeman

How do I execute the below in Rise 360

function findLMSAPI(win) {
// look in this window
if (win.hasOwnProperty("GetStudentID")) return win;

// all done if no parent
else if (win.parent == win) return null;

// climb up to parent window & look there
else return findLMSAPI(win.parent);
}

var lmsAPI = findLMSAPI(this);
lmsAPI.SetReachedEnd();