Restrict access to course for x hours

Feb 28, 2019

So here is a nice little problem to solve :)

I have a client who wants a course where you can get so far and then stop when you get to a certain point.  They then want access to the rest of the course (just a custom next button really) restricted for 12 hours from the point where the learner stops (its something to do with reflection time).

I am trying to avoid development to our LMS for this one course so I am looking for ways to do it in Storyline.  My thinking is that I can use Javascript to get the current date/time, set some kind of timer for 12 hours and disable the next button.  Then once the 12 hours has expired the button will become available.

Obviously the learner isnt going to leave the course open for 12 hours so I am assuming I'd need to write the current date/time and/or the +12 hours date/time into variables and then do some kind of comparison when the learner reopens the course.

Does anyone with any Javascript experience have any idea where I could even start with this?  I won't be doing the coding myself as we have developers here who know a lot more about it than I do, but I will need to give them some kind of brief to work with.

5 Replies
Allison LaMotte

Hi David,

A community member recently shared a Storyline project where he restricted access to content by date. I'm not sure if this will work for your purpose since it's not a specific date you can pre-program, but an amount of time after the learner first accesses the course but I thought I'd share it with you just in case it's helpful: Date locked questions.

If that doesn't work, hopefully some Javascript rockstars will jump in here and help you figure this one out.

OWEN HOLT

Trigger the following code in your SL file to set a target time after which the user can resume. This example uses a shorter 5 minute time out.
//get the current date and time and add 5 minutes to it
let d = new Date(); d.setMinutes(d.getMinutes() + 5);

//convert the date time to a numeric value
let target = d.valueOf();

//StoryLine is buggy when saving numeric variables over multiple sessions
//change the value to a string
target = target.toString();

//Send the string to StoryLine
var player=GetPlayer();
player.SetVar('Reflection', target);

Then on your next button, execute the following JS:
// Establish StoryLine player connection and get timer target
var player=GetPlayer();
let d=player.GetVar('Reflection');
let target = new Date();
target.setTime(d);

//Measure elapsed time
let now = new Date().getTime();
let distance = target - now;

//state any remaining time in terms of minutes and seconds and restate negative values as 0
let mm = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
let ss = Math.floor((distance % (1000 * 60)) / 1000);
if (mm < 0) {mm = 0;}
if (ss < 0) {ss = 0;}

//Return remaining minutes and seconds to SL
player.SetVar('Minutes', mm);
player.SetVar('Seconds', ss);

On the next button add the conditions to allow advancing only if both the minutes and the seconds variables are equal to 0 else, show a layer or some other message to let the user know not enough time has elapsed.

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