Java script in Storyline to set the Results.ScorePoints variable?

Apr 19, 2013

Seriously, this seems so simple, but I just can't seem to find the magic scripting or sequence to make this work.

All I want to do is execute a java script when clicking a button.  The java script I'm trying to formulate has to do one thing:  set the "Results.ScorePoints" variable equal to my "NumberRight" variable.  Is there an easy way to do this?

Or is there an easier way to accomplish this:  I have one slide with 10 draggable items which need to be dropped on 1 of 2 drop targets.  To pass this 'quiz', I require that at least 8 out of 10 of the items be dropped correctly.  They don't ALL have to be correct (which is what the default Storyline Drag and drop interaction scoring wants).  I've got the interaction working perfectly using states/triggers/layers, but my problem is the Results slide...keeps sending me to the Fail layer if I have 8 or 9 correct due to the "Results.ScorePoints" variable = 0 ; it should go to the Success layer and that's why I'm trying the java script idea to set that Results.ScorePoints variable  (if 10 out of 10 are correct, everything works fine).

Any ideas?

32 Replies
Steve Flowers

With Moodle, this should work:

var player=GetPlayer();
var customScore=player.GetVar("TotalTokens");

//get LMS API
lmsAPI = parent; //no var!
//set score; the first number is the score
lmsAPI.SetScore("TotalTokens", 100, 0);

Storyline will try to overwrite your forced score. So make sure you either override the score function or create a condition that will never be reached (track by slides viewed and create a slide that cannot be reached or track by results in a scene with a question that cannot be reached.)

If you want to track interaction submissions from a question bank, it's best to override the score function. To do this, create a Javascript trigger at the root of your Master slide. In the JS trigger, add this:

ReportStatus=function(){}

This will override the function that Storyline calls to write the score and status to the LMS. This way, Storyline will never try to ruin your customized write.

James Bonney

Thank you Steve, really appreciate your help.

Here's what I've done but to no avail.

  • I put the 1st JS you mentioned on the results slide, as the first trigger 'when timeline starts'.
  • Added the 2nd JS you mentioned on the MasterSlide view 'when timeline starts'
  • I've created a new slide that cannot be visited and tracked the completion by slides visited (all must be visited) - The JS seems to be forcing the LMS learning record to show as passed which is good, but the 'TotalTokens' value isn't showing.
  • I tried 'unassigning' the 'Submit Results' trigger and having it active when timeline starts (after the JS trigger).

The users 'TotalTokens' number variable which is what i want the Grade on the LMS to display can vary from 10 - 204,000.

Do I need to adjust the reporting settings within the LMS? Any plug-ins etc?

I'm happy to send you the source file for you to have a look around if that helps make it clearer?

Paul Kizilos

I know this is an ancient thread - but just in case someone Googles their way here....

There is a simple error in your javascript. Once you declare the variable customScore, that is what you should pass in the lmsAPI.SetScore function. See below.

var player=GetPlayer();
var customScore=player.GetVar("TotalTokens");

//get LMS API
var lmsAPI = parent;
//set score; the first number is the score
lmsAPI.SetScore(customScore, 100, 0);

Laurel Thomas

I'm trying to follow the JavaScript, but I admit I'm not a programmer. I don't get if we still have to use a quiz question and results slide - even if they are hidden - or if JS can be used alone (hence using it as a "workaround" if you want to report a score to an LMS without a quiz).

My variable is called Score. It is already out of 100 points -- the learner starts at 100% and has points taken away based on selections. This is what I have so far:

var player=GetPlayer();
var customScore=player.GetVar("Score");

//get LMS API
var lmsAPI = parent;
//set score; the first number is the score
lmsAPI.SetScore(customScore, 100, 0);

I also added the ReportStatus=function(){} code to the Master slide. What else am I missing? Thanks.

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