Storyline

Creating a Timer in Storyline with JavaScript

Here is a quick and easy JavaScript snippet that you can put inside Articulate Storyline 360 to create a timer independent of the Storyline timeline. This JavaScript snippet allows you to create game elements for the learner that they can control.

When the timer is up, you can also show layers, jump to other pages or disable buttons on the page. You can do a lot inside Storyline with this simple snippet, and this Storyline and JavaScript tutorial will help you get started.

//Getting the player
const player = GetPlayer();

//Where to start
let sec = 0;

//Set up the timer
function startTimer(){
  sec += 1;
  player.SetVar("timer",sec);
  if (sec == 100) {
    clearInterval(timerId);
  }
}

//Start the timer
timerId=setInterval(startTimer,1000);
            
Jeff Batt
17 Jan, 2023