Forum Discussion
Sending Points to the LMS using Javascript
TristanDF In case anybody else stumbles across this, I can see an issue with this piece of code:
var quizScore = player.GetVar("Results.ScorePercent");
Storyline wont allow you to access these pre-defined variables. In order to access the "Results.ScorePercent" variable, in Storyline, you would need to define a new variable to assign the value of "Results.ScorePercent" to. For example "ResultsScorePercent", and then assign the value of "Results.ScorePercent" to it. You can then use this:
var quizScore = player.GetVar("ResultsScorePercent");
This would have been a major issue in the above code, as "quizScore" would not have been set with the expected value. Possible an "undefined" or "null".
A good method is to use your browser console to track the values of all the variables you are working with, so you can see where the script is going wrong.
var player = GetPlayer();
var customScore = player.GetVar("customScore");
console.log("customScore",customScore);
var quizScore = player.GetVar("Results.ScorePercent");
console.log("quizScore",quizScore);
var finalScore = quizScore + customScore;
console.log("finalScore",finalScore);
// Set the final score (0-100 scale)
lmsAPI.SetScore(finalScore, 100, 0);
// Mark the course as completed
lmsAPI.SetReachedEnd();
- MathNotermans-92 months agoCommunity Member
Sam is right. Always use custom variables when setting / getting with javascript.