Documentation
Using PlayerUtils wrapper
We have prepared a wrapper object called PlayerUtils, which allows you to get all most important score details in a few easy steps. Here are two examples showing how to use it.
Simple get score object
var player;
function icOnAppLoaded(){
player = icCreatePlayer('_icplayer');
player.load('content/default.ic.xml');
player.onPageLoaded(function() {
var eventBus = player.getPlayerServices().getEventBus(),
listener = function() {},
utils = new PlayerUtils(player),
presentation = utils.getPresentation(),
scoreObject = utils.getPresentationScore(presentation);
console.log(scoreObject);
});
}
More complex example
In this example, you are listening for the event ShowErrors, which is called when a user selects Check or Submit button. Then you check if it was the first ShowErrors event triggered on a current page. You can save the result to your database and let the user correct eventual mistakes.
var player;
function icOnAppLoaded(){
player = icCreatePlayer('_icplayer');
player.load('content/default.ic.xml');
var checkCounter = {};
player.onPageLoaded(function() {
var eventBus = player.getPlayerServices().getEventBus(),
listener = function() {},
utils = new PlayerUtils(player),
presentation = utils.getPresentation();
listener.onEventReceived = function(eventName, eventData) {
var scoreObject = utils.getPresentationScore(presentation),
maxScore = scoreObject.maxScore,
score = scoreObject.score,
pageIndex = player.getPlayerServices().getCurrentPageIndex();
if (!(pageIndex in checkCounter)) {
checkCounter[pageIndex] = 0;
}
if (checkCounter[pageIndex] == 0) {
console.log('First Check. Save to Database.')
console.log(scoreObject.paginatedResult[pageIndex]);
} else {
console.log('Next Checks. Give more coins.')
console.log(scoreObject.paginatedResult[pageIndex]);
}
checkCounter[pageIndex]++;
}
eventBus.addEventListener('ShowErrors', listener);
});
}
Remarks
- Check also PlayerService functions. Especially the section with score functions.