JavaScript, functions and arguments

Nov 30, 2015

Hi,

I was wondering if there is a comprehensive list somewhere of all of the SL2's player functions?

I've found this but it's two years old.

All I'm looking to do at this point is to have a button on a slide, that when clicked set a variable to that slides number (just to be clear by number I'm referring to Scene.Slide)

I've tried the following with no success, I normally get the variable (named detail) showing 'Null' on the slide.

var SlideNo = player.currentSlide
player.SetVar("detail",SlideNo);

I've also tried using player.showSlideID() & player.showSlideIndex(). 

Should I be placing something as an argument or am I using the wrong function?

Thanks,

David.

 

 

17 Replies
Ashley Terwilliger-Pollard

Hi David,

We want every feature in our software to work well. With that goal in mind, we've decided not to document Articulate Storyline system variables that could be accessed via JavaScript triggers at this time.

Storyline isn't currently designed to expose system variables for user interaction. As a result, JavaScript triggers that reference them could interfere with course playback.

We value your feedback and want to better understand your needs, so we can build even better software. Help us plan for the future. Send us your feature requests with specific system variables you'd like to see and examples of how they could be used.

Hopefully others in the community who have looked into accessing these or creating a slide number/tracking set up will be able to share that here. 

David Blanchard

Thanks Matthew. 

I was hoping I won't have to do it that way, I know it's not much work to do manually but it's still something I'd rather automate.

Following on from this I have a form that people will be using to provide feedback on a per slide basis, that's why I wanted to grab the slide number from the player. The user can then click a link from any slide to open up the feedback form with the Slide number pre-populated by passing the variable as a parameter in the URL.

What I want however, is instead of having a link and a new window opening each time is to have a lightbox slide with a web object showing the form yet still pass the variable as a parameter.

I'm struggling to add the web object and pass the parameter. Is there a way to use JavaScript to load a web object rather than inserting one from the ribbon? If there is I'll be able to launch the web object with the relevant parameter.

Cheers,
David.

David Blanchard

Yes, it's a review tool. Appreciate the suggestion of Review My eLearning but it's not for me I'm afraid.

I've got a button on a slide that when clicked opens a feedback form in a new window and pre populates a field on the form with the slide number. It does this by using JavaScript extracting the value of the slide number variable and adds it onto the end of the link as a parameter. That works fine.

What I'm looking to do is not have it open in a new window. What I'd like is to have the form open in a web object on a lightbox slide so the user doesn't have to 'leave' the eLearning.

When inserting a WebObject from the ribbon I'm unable to add the parameter to the end of the URL. What I'm looking for is some JavaScript that launches a WebObject on a slide, if I can do that I can specify the URL including passing the parameters.

Thanks,
David.

David Blanchard

I've sort of got it working...

I'm using the code:

var number = player.GetVar("slideno");
var link = "url?parameter="+number;

OpenWebObject(1,link,0,0,720,520,245,52);

var oWebObject1 = g_oWebObjects["1"];
oWebObject1.Div.style.zIndex = 900 ;

When I click the button to open the lightbox slide on which the code is on, the web object isn't linked to the slide - it's sitting on top of the player. When I click to close the lightbox slide the web object sometimes stays open, like it's not linked to the lightbox slide.

I've attached the file I'm working on.

Dave Cox

Hi Luke,

The var slideno referenced above is a variable created in the storyline variables panel.

The javasscript code "var player = GetPlayer();" gets the storyline player object and stores it in the javascript variable player.

The javascript code 'var number = player.GetVar("slideno");' gets the value of the variable slideno and stores it in the javascript variable number.

You can also use SetVar to update the storyline variable. The code SetVar("slideno",number) will update the storyline variable slideno with the value of the javascript variable number.

 

onEnterFrame (James Kingsley)

Sorry for the delayed reply to this. 

Unfortunately there are no 'system variables' in Storyline. The suggestion is that you create a Storyline variable named 'slideno' and update it on every slide with a timeline start trigger. Of course that can get messy if you move/add/delete slides so you may want to wait until the course is pretty complete before setting those triggers.

 

Sachin M

I am replying to this quite late,  but might be useful for someone in need.

currentSlide is not a variable, it is a function. it will return an object containing information about the current slide.

So you may use:

var player = GetPlayer();

var currSlide = player.currentSlide();

var slideIndex = currSlide.sceneIndex;

Hope this helps. someone . :)

Note: I have attached an excel containing all properties and methods of player and slide. Contact me if you need any information on the same or related.

Sachin M

This should work for 3 as well as 360, I'll check and update, meanwhile, sharing an updated version with interactions and attempts. These contain the score, result and attempt values

Note: For getting the values, you will need to access them for previousSlide, for ex:
player. previousSlide.interactions[Object.keys(player.previousSlide.interactions)[0]]

later i will  try to make a story file which will out all of this to the console.

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