Order of Triggers using Javascript

Mar 18, 2015

I know triggers on a slide are supposed to execute in order, however I have a situation where the second trigger starts before the first trigger ends.

Trigger 1 - Execute JavaScript
    This gathers cookies from the calling application and assigns them to variables in the storyline course.  For example SMART = True  (Smart is a text variable)

Trigger 2 - Check if Smart is True and jump to slide xx

Trigger 2 never works.

So I put trigger 2 on the second slide.  When the course launches, I hit next to go to slide two and now the trigger works.

It seems to me on the first slide where I had triggers 1 and 2, that trigger 2 ran before trigger 1 was complete.  Both Triggers are marked to run when the timeline of the slide starts.

Is there a way to force trigger 2 to wait until trigger 1 finishes?


5 Replies
Steve Flowers

Ramon - 

Triggers will begin execution in order. However, because JavaScript is executed synchronously (even though your triggers are executed sequentially) your second trigger may eval a value that the first trigger hasn't yet set. A few ways around this, here's how I'd do it:

Javascript trigger:

//execute all of your stuff.

//Set SMART to true or not

//Increment a storyline variable

var player=GetPlayer();

var remoteTrigger=player.GetVar("rtrigger");




//you could also do this with a true / false variable... possibly using your SMART variable to trigger the jump.


In Storyline:

Setup a When variable changes event to jump to the next slide. This creates a listener that will trigger your action whenever the variable changes. As mentioned in the comment above, you could use your SMART variable to trigger the advance (When Variable Changes SMART, jump to next slide if the value == true).

The remote trigger and listener method is handy for lots of things including communication between the master slide and the base slide.


Steve Flowers

The problem I've found with time delays, sometimes these are exceeded by the execution of script since the browser's JS engine shares clock cycles with everything else. Rarely do these exceed tenths of a second but I've seen stuff hang for half a second or more if I've got video processing, video running, etc...

Ramon Smitherman

Hi Steve,

I appreciate your input.  With your input on how this might be happening I made some changes and am very please with how this works. I split up some of the JavaScript logic on different layers.  The primary JavaScript that starts was changed to start after a 1 second media files timeline finishes.  It is 1 second of silence.  The rest of the JavaScript is on layers which are triggered based on values of variables.

For anyone wishing to track training without an LMS, for example SharePoint, I have worked out how to communicate to and from Storyline from an outside application.

The overall concept was to place all my scripts and logic in a single slide and make it the first slide of the course.  It is removed from the menu and only displays for 1 second before jumping to the Opening slide of the course. All communication to and from the course is via cookies.

Then anywhere in the course I change a variable to "Update" and jump back to slide 1 to do the updating to the external application.

There are two reasons for this approach.

1. It is very easy to implement

2. When jumping out of a course, the remember where you left off,  always starts at the beginning of the course. 

I have attached a storyline course to be used for testing and the implementation instructions.  I realize you need to have access to SMART to fully test this but with the Story file and instruction anyone should be able to adopt it to their own application.


You previously worked with me on getting Cookies to work with Storyline through JavaScript.  The solution to that is included in the Story file.  Turns out the set cookie command needed to end with /path

Jill Freeman
Steve Flowers

Triggers will begin execution in order. However, because JavaScript is executed synchronously (even though your triggers are executed sequentially)

Hi Steve. I am a JS novice. When I add multiple js in the Execute javascript trigger, do you mean they all fire consecutively? Or do they execute in order from top-down?