Pass score to LMS via javascript: for example passing based on viewing mandatory chapters

May 27, 2016

In a forum I found a question if it was possible that you have to view specific chapters in a module. For example, the module is passed when chapter 1, 2 and 5 are viewed, while chapter 3 and 4 are optional. This is possible when you pass a score directly to an LMS via javascript.

Because I want to check this feature I worked out an example to learn from it and I want to share here what I learned with attached examples I explain in this post.

JavaScript needed

I found the following javascript can be used to call the LMS API and set the score and status:

//get LMS API
var lmsAPI = parent;
//set score; the first number is the score
lmsAPI.SetScore(100, 100, 0);
//set status; possible values: "completed","incomplete", "failed", "passed"
SetStatus("completed");

Tip

Use a free https://cloud.scorm.com account to test this through until it works flawless and pass the score and status correctly. For example, the code I found did not pass the status until I put a ; at the end of the last line as in the example above.

First simple example

First I defined an empty result slide:

It might work without, but at least it will define the masteryscore correctly in the LMSmanifest file. Maybe someone can confirm the need.

Then I created three test buttons and attached the javascript to it with different pass grades. When clicked  show a layer with the message that the results were passed. I tested this with https://cloud.scorm.com until it worked. Huray. See my first attached example with the result.

Second example: work with Chapters

Now I understood I worked on the question:

For example, in each mandatory chapter you can set a true/false variable, for example "chapter1Complete=true when the learner visits a specific page in this chapter. In attached example I used a common Storyline tab template to make it a bit easier for testing. Visiting each tab set's a variable for example Complete1=true etc. My exercise is to make tab 1, 2 and 5 mandatory for completion.

To pass the score I used the button from the first example.

The user get's a visual clue that each tab is visited. When you design chapters you also must design something that the user know it's completed by a visual clue. In the TAB display it's done by states. When visitied, the state of the tab changes and display a checkmark.

Pass the complete score when tab 1, 2 and 5 are visited

I do not want that a learner pass the score when not all mandatory tabs have been viewed. Then the LMS gets a score (failed) and if you for example set in the LMS that you may do a limited number of tries, this can go wrong.

So I did not add the javascript to the button, but instead display a "Complete Layer" or "Incomplete layer". The Complete Layer pass the score to the LMS when the timeline for that layer starts.

To make it visually clear, the state of the button changes when the mandatory tabs (1, 2, 5) are visited. You can do this by checking if all the variables Complete1, Complete2 and Complete5 are all set to true. However, in this case it's a bit easier to set the button on complete when the states of the tabs 1, 2 and 5 have been changed. Either way, both will work.

Attachments

example 1: Pass the score to the LMS manually: click a button to pass a specific score
example 2: view tab 1, 2 and 5 to be able to complete the course

More links

https://support.elearningbrothers.com/entries/23642122-Passing-over-Storyline-Game-data-to-your-LMS

5 Replies
Mayur Raskar

I want to to show customized score in LMS using java script, but in LMS my Score showing "unknown" result. Please help.

Here is the JavaScript i used for that:

var player = GetPlayer();

var lmsAPI = parent;

var myScore= player.GetVar("LMS");

lmsAPI.SetScore(myScore, 100, 80);

SetStatus(“completed”);

 

Attached is the LMS screenshot.

Vijay Paturkar

Below script works perfectly:

Here, I am translating the points accumulated in the user variable "TotalScore". Below JavaScript is inserted in the "Results" slide in Articulate Storyline. Remove the default Submit results trigger, and then insert below JavaScript.

--------------------------------------------------------------

var myscore = 0;
var player = GetPlayer();
var ptScore = player.GetVar("TotalScore");
var maxPoints = 330;
myscore = 100*ptScore/maxPoints;

SCORM2004_SetScore(myscore, 100, 10);
SCORM2004_CommitData();

--------------------------------------------------------------