Accessing Results.ScorePercent through Javascript

Greetings,

I am a long time e-learning and javascript developer. I had previously built a quiz results animation for my client which showed what percentage of the quiz the learner got correct.

The information I needed from Storyline to create this animation was very simple. Just the score percent. This is available in Storyline as the Results.ScorePercent variable which is available inside the Trigger Wizard.

This animation worked in Storyline 2. Now that we have upgraded to Storyline 3 it does not.

 

The Storyline 3 Javascript help (https://articulate.com/support/article/Storyline-3-JavaScript-Best-Practices-and-Examples) indicates that storyline variables should be available through the GetPlayer().GetVar() method.

However, when I try...

 GetPlayer().GetVar("Results.ScorePercent");

...I get null in return.

In Storyline 2 I used to be able to access this information via...

function getQuizData(){
var quizList = window.story.quizzes;
var firstQuiz = quizList [Object.keys(quizList)[0]];
return firstQuiz.variables;
}

var quizData = getQuizData();

var percentScore = Math.round(quizData.PercentScore) + "%;

...In Storyline 3 it seems that the 'story' window object has been moved inside an anonymous function, making it inaccessible.

I tried adding text fields to the stage displaying the Results.ScorePercent variable and then reading their text. But it seems as of Storyline 3 this text is generated inside a SVG canvas and is therefore, once again, inaccessible.

So my question is as below. 

  • Through Javascript is there any way to read the Results.ScorePercent variable?
  • Through Javascript is there any way to access the 'story' object any more?
5 Replies
Marcia Witt

Hi Tristan!

Did you ever happen find an answer to this?

I am also trying to get this variable via JavaScript as follows:

var theScore =(

player.GetVar("Results.ScorePercent")

)

The display works perfectly in the slide but I want to print the score on an external printCertificate.html page--name and date is working for me. All I get is "null" for this variable.

This should be easy based on the article above...

Regards,

Marcia

 

Tristan Ward

Hi Marcia,

I did actually find a work around for not being able to access the Results.ScorePercent variable. While  Results.ScorePercent is not accessible through the player.GetVar() function, user variables are.

So on the results slide I added two triggers which put the value of Results.ScorePercent and Results.PassPercent into two different user variables called percentScore and passPercent.

In the export I was able to access those variables with:

player.GetVar("percentScore")
player.GetVar("passPercent")

That said, I don't know if that will work for you though. If you're in am 'external printCertificate.html page' then the 'player' Javascript object should not be accessible there because it is part of the Storyline HTML page.

Tristan, 

Marcia Witt

Hi Tristan,

This worked beautifully!!

Initially I tried file.html?print= to place the Results.ScorePercent in the
URL string to no effect. Then I tried to set Results.ScorePercent to
another user variable in a variety of ways and spots and got only a null
value. But adding Results.ScorePercent to percentScore when the timeline
starts worked perfectly.

And, fyi, it will output to an external html file using GetPlayer. And I
had to use the following syntax:

var player = GetPlayer () ;

var theScore =(
player.GetVar("percentScore")
)

var urlstring = ("printCertificate.html?print=" + theScore);

Thanks so very very much!
Marcia

Johnny O'Barr

Hello, I am trying to figure out how to create a course with branched content leading to two different quizzes. Once the user takes one of the quizzes, I would like the quiz results to show a percentage that matches only the questions the user took. For example, the first 5 slides lead to a 6th slide that asks the user to pick a path. They pick the path, complete an additional 5 slides and then answer 10 quiz questions. There are another 10 questions on the other path they will not answer. I would like the quiz results to say 100% if they passed all 10 questions on their path. Is this possible using javascript? I feel like what you have talked about in this thread sheds a little bit of light on what I'm trying to do, hence me posting this here when it might seem a bit unrelated.