Forum Discussion
GetScore from Moodle
I am trying to have when students retry an activity they have their current best score displayed as an incentive.
I am struggling to get the GetScore(); value to return the previous highest score attempt from Moodle. The console shows a blank result and the storyline variable keeps coming back blank when I set as text or NaN when I set as a number.
I have tried varaiations of the following without success, (yes there is a score recorded on the LMS to access).
var lmsAPI = parent;
var player = GetPlayer();
var myScore = GetScore();
console.log("test "+myScore);
player.SetVar("pastscore", myScore);
Does anyone have a simple working version they can share so I can learn from?
- Jürgen_Schoene_Community Member
try
var myScore = lmsAPI.GetScore();
https://community.articulate.com/discussions/articulate-storyline/using-lmsapi-getscore
here is a solution, if lmsAPI not found (if it's not parent)
function findLMSAPI(win) {
if (win.hasOwnProperty("GetStudentID")) return win;
else if (win.parent == win) return null;
else return findLMSAPI(win.parent);
}
var lmsAPI = findLMSAPI(this); - CameronHallo868Community Member
Thanks Jurgen for the reply I have tried your solution without any joy. I am using Moodle 3.9 as the LMS and have tried both 1.2 and 2004 SCORMS.
This code gives a blank value in the console.log
And just this code tells me it isn't a function.
var myScore = lmsAPI.GetScore();
console.log("mm "+myScore);Sorry obivously doing something basic wrong.
- Jürgen_Schoene_Community Member
there seems to be a script error in your code -> result: storyline cannot start it -> "is not a function"
you could check your code on https://beautifytools.com/javascript-validator.php
######
whats the result with
console.log( "ID", lmsAPI.GetStudentID() )
this is the result on Scorm Cloud with one of my courses
lmsAPI.GetScore() is always empty - perhaps the score will be never sended ?
here you can see how to debug the communication between course and LMS
https://community.articulate.com/articles/the-secret-to-lms-debugging