JavaScript Help
Sep 22, 2014
Does anyone see anything wrong with my JavaScript below? I've got this being executed on a slide just after a trigger that submits to the results slide, but nothing is happening.
var player = GetPlayer();
var totalScore = player.GetVar("Results.ScorePoints");
var finalScore = Math.floor(totalScore/100);
player.SetVar("FinalScore", finalScore);
alert("Results.ScorePoints = " + totalScore);
alert("finalScore = " + finalScore);
The "alert()" lines are in there just to test, but they are not executing. Also, I have a %FinalScore% reference in a text field on that page, and it's showing 0 even though I know I'm entering the correct answers on the quiz questions.
This is my first Storyline project after 20 years of using other tools. Please help me figure out what I'm doing wrong. What additional info do I need to provide?
Thanks.
4 Replies
Oh, and yes, I created the "FinalScore" variable in Storyline as a "number" variable with a starting value of 0.
Upon further testing, I found that the quiz is being scored, and the correct number is in "Results.ScorePoints," but for some reason, the JavaScript doesn't seem to be triggering. Here's my triggers panel for that page...
Here's what the trigger looks like when I edit it...
Here's the JavaScript as it appears in Storyline...
Figured it out... After digging around some more, I found that I can't directly access "Results.ScorePoints" in my JavaScript. I had to create my own variable and set it to the value of "Results.ScorePoints," and then use my variable in the JavaScript. Now it works fine.
Final version of JS is...
var player = GetPlayer();
var totalScore = player.GetVar("RawScore");
var finalScore = Math.floor(totalScore/100);
player.SetVar("FinalScore", finalScore);
alert("Results.ScorePoints = " + totalScore);
alert("finalScore = " + finalScore);
"RawScore is set to the value of "Results.ScorePoints" using an "adjust variable" trigger.
This discussion is closed. You can start a new discussion or contact Articulate Support.