The sample zip file posted here in articulate community contains an example of WebObject sending SCORM variable
to LMS. Published output has two javascript files. WebObject uses these
two files.
- story_content/custom.js: This file acts as bridge between Storyline variables and WebObject. WebObject uses custom.js file to communicate with LMS and also to update the Storyline variables on slide for display.
- webobject/scripts/main.js: WebObject uses main.js for all its internal logics.
// custom.js
// JavaScript Document
var findAPITries = 0;
var lmsAPI;
var gameScore = 0;
function findAPI(win){
while ((win.objLMS == null) && (win.parent != null) && (win.parent != win))
{
findAPITries++;
// Note: 7 is an arbitrary number, but should be more than sufficient
if (findAPITries > 7)
{
alert("Error finding API -- too deeply nested.");
return null;
}
win = win.parent;
}
return win.objLMS;
}
function getAPI()
{
var theAPI = findAPI(window);
if ((theAPI == null) && (window.opener != null) && (typeof(window.opener) != "undefined"))
{
theAPI = findAPI(window.opener);
}
if (theAPI == null)
{
if (_Debug) // BMD added
alert("Unable to find an API adapter");
}
return theAPI
}
function init(){
lmsAPI = getAPI();
}
function GetPlayer()
{
var player = parent.GetPlayer();
return player;
}
function setVariable(varName, varValue){
var player = GetPlayer();
player.SetVar(varName, varValue);
setScormScore();
}
function getVariable(varName){
var player = GetPlayer();
gameScore = player.GetVar(varName);
console.log("gameScore=" + gameScore);
console.log("cmi.core.score.raw=" + getScormScore());
}
function setScormScore(){
var blnResult;
blnResult = lmsAPI.SetScore(gameScore, 100, 0);
console.log("Returning " + blnResult);
return blnResult;
}
function getScormScore(){
var sLearnerScore = lmsAPI.GetScore();
return sLearnerScore;
}
init();
// custom.js ends here
------------------------------------
// main.js
// JavaScript Document
function setGameScore(score){
gameScore = score;
setVariable("gameScore", gameScore);
}
function getGameScore(){
getVariable("gameScore");
}
function setGameScore(score){
gameScore = score;
setVariable("gameScore", gameScore);
}
function getGameScore(){
getVariable("gameScore");
}
No comments:
Post a Comment