Can you pass SL results variables on to Javascript?

Jun 01, 2012

Can you pass Storyline results or scoring variables on to Javascript?

e.g:

var player = GetPlayer();
alert("Your score is, " + player.GetVar("Results.ScorePoints") + ".");

Doesn't work but:

var player = GetPlayer();
alert("Your score is, " + player.GetVar("MyName") + ".");

does (note: "MyName" is a standard text variable).

Thx

Graeme

23 Replies
Steve Flowers

Hi, Graeme - 

You'll need to first transfer the score into another variable to get it passed through JavaScript. I think the GetPlayer method only grabs author generated variables. I haven't been able to pull any of the compound objects using that method.

Modify Variable myVariable to Results.ScorePoints when slide timeline starts.

alert("Your score is, " + player.GetVar("myVariable") + ".");

Bengt Gustafsson

Hi,

I tried to do this bu cannot figure out how to:

"Modify Variable myVariable to Results.ScorePoints when slide timeline starts."

When I try to do this I cannot see the "Results.ScorePoints" listed as a possible variable to use but "Results.ScorePoints" is listed among the variables.

Can you explain?

Thanks,

Bengt

Bengt Gustafsson

Hi Graeme,

Thanks for the quick reply. Yes I have the Results.ScorePoints variable created at the result slide and listed among the variables.

But the problem is that I cannot when I try to "Adjust" the variable and "Assign" it to "
myVariable" in the trigger setting the "Results.ScorePoints" variable is not listed there and possible to select. Am I looking in the wrong place or is there another solution to Assign the variable?

Thanks,

Bengt

Mike Bethany

Phil Mayor said:

You cannot adjust the result variable but you can send it to javascript.

Steve just a thought could you send the result to javascript and the adjust the result score in javascript and send it back, not tried it but it might be possible


I'm assuming since you're wondering if you can set Results.ScorePoints when you say that you can send Results to JavaScript you mean you can directly read the variable using player.GetVar("Results"). My experience is this is not the case. I must first copy the results variable value that I want into another variable. This is a bit of a pain with a course with lots of Results objects but it's not hard.

Josh Davis

Hi Team,

Just to add to the above, has anyone had any success passing this outside of articulate with the JS?

I have used one of Steves other js examples and the GetPlayer method to create a custom 'Certificate of Completion', however I need to find a solution to get the results from SL across to this new window, and cant work out how to take the results variable and push it in to a new variable for export.

Massive longshot, and probably incredibly difficult but worth the try...

Kaye Lirio

Hi All,

I am fairly new to Storyline and your posts have been very helpful.  However, I am just confused as to how to extract the result value from the Result page and export it through Javascript to an outside file like a .txt file.  Is this possible please? 

Thank you very much, I really appreciate your help on this.

Kaye

Cédric Froehlich

Hi all!

Don't know if this will answer the problem, but there's a bit a code on the support site of Articulate. Here is the code for the export of variable that are edited by user (in this example, there are name and mail).

var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.OpenTextFile("C:\\Test.txt", 8, true, 0); // Replace the bold part with your file location

var name = player.GetVar("TextEntry");
var email = player.GetVar("TextEntry1");
s.WriteLine("Email: " + email);
s.WriteLine("Name: " + name);
s.WriteLine("==========");
s.Close();

For the score part, personnaly, I create by myself all the variables for result. If I got a quiz, I set a trigger on the Continue button of the feedback layer to modify my result variable.

Once this done, you can do whatever you want with this variable:

- Get it in a text file with the code upside,

- Call it on a slide or a text box or any objet with text and making it appearing at the start of the timeline,

- Or whatever you want! It's a variable, you can call it back as you want!

Hope iut can help you!

Trip Levine

Mike Bethany said:

Phil Mayor said:

You cannot adjust the result variable but you can send it to javascript.

Steve just a thought could you send the result to javascript and the adjust the result score in javascript and send it back, not tried it but it might be possible


I'm assuming since you're wondering if you can set Results.ScorePoints when you say that you can send Results to JavaScript you mean you can directly read the variable using player.GetVar("Results"). My experience is this is not the case. I must first copy the results variable value that I want into another variable. This is a bit of a pain with a course with lots of Results objects but it's not hard.


Mike Bethany, I see you said, you would assign the results variable. But how? I made an Adjust Variable trigger, the variable is Answers ( something i made up ), operator is = Assignment ( pretty sure that's right ), the value is Variable ( also I'm pretty sure that's right ), and the value I have is Results from my Results page. Their variable, not mine.

But when I do player.GetVar('Answers').. I would expect a hash or some sort of integer representing the results. Instead I get the string "ScorePoints".. What am I missing here? I can't actually assign as a variable Results.ScorePoints.

Little Man Project

I've been trying to implement the solutions outlined in this (and several other) post on the issue of passing quiz results to an LMS but can't seem to get it to work.

I have a course with two paths a learner can choose from.  At the end they complete a quiz based on the content they have reviewed.  Obviously I can't have two result slides being passed to the LMS and if I use the 'result of results' option it averages the score (so basically divides the score in half as they only complete one of them).

So I have set up a Variable that takes the Result.ScorePoints figure and a Javascript that then passes that variable to the LMS.  However, I've been testing this out in a short demo version in SCORM Cloud and it doesn't work :-(

Could someone take a look and see if they can spot the problem?  The new variable is getting the Result.ScorePoints OK so it seems to be the Java bit that isn't working.

Little Man Project

I managed to track down the issue in this file and thought I'd post here in case anyone else came across the same issue (or this thread).

When copying and pasting the code provided above, you need to change quotation marks to the ones on your keyboard.  The ones above are converted into a web format which will stop the java script working.  

Its a hard error to spot, but makes all the difference! 

This discussion is closed. You can start a new discussion or contact Articulate Support.