Java script in Storyline to set the Results.ScorePoints variable?

Apr 19, 2013

Seriously, this seems so simple, but I just can't seem to find the magic scripting or sequence to make this work.

All I want to do is execute a java script when clicking a button.  The java script I'm trying to formulate has to do one thing:  set the "Results.ScorePoints" variable equal to my "NumberRight" variable.  Is there an easy way to do this?

Or is there an easier way to accomplish this:  I have one slide with 10 draggable items which need to be dropped on 1 of 2 drop targets.  To pass this 'quiz', I require that at least 8 out of 10 of the items be dropped correctly.  They don't ALL have to be correct (which is what the default Storyline Drag and drop interaction scoring wants).  I've got the interaction working perfectly using states/triggers/layers, but my problem is the Results slide...keeps sending me to the Fail layer if I have 8 or 9 correct due to the "Results.ScorePoints" variable = 0 ; it should go to the Success layer and that's why I'm trying the java script idea to set that Results.ScorePoints variable  (if 10 out of 10 are correct, everything works fine).

Any ideas?

32 Replies
Steve Flowers

Hi Brenda - 

Unfortunately, you cannot write to the Results.X variables. The way I usually handle drag and drop or multi-part interactions that need to be graded is by making them a true / false question and hiding the true / false guts. If they get the activity right, I set the state of true to selected if not, false is selected. When graded, this is either right or it's wrong. That makes it easy for results calculations, especially if you have multiple questions or are running a bank. 

It's a fake-out. But it works

Steve Flowers

Hi, Rebecca - 

Here's an example of what I mean This basically proxies the interaction to the true / false question in the background. The neat thing about this is you can allow for multiple tries and leverage the feedback layers without much fuss. This also lets you score long interactions as "aggregate achievements."

The secret is setting up your triggers for the interaction. In this one, I:

  • Added correct and incorrect states to the draggable items;
  • added two triggers to each draggable object, one for the correct drop and one for the incorrect drop. The visual states of these objects are identical to the Normal (no hints);
  • and setup a "listener" trigger to set the true / false objects according to the logic of the states of the draggable items. i.e., if ANY of the objects states are incorrect, set the "False" object to selected. If ALL of the object states are correct, set the "True" object to selected.

I also set the False object to selected when the timeline starts. This ensures that the right feedback is generated if the participant doesn't drop any shapes. When you set shapes as a drop target (the shapes on the right in this case) you get additional options in your context menu. This gives the same control you have with the question type and freeform for shape stacking, etc..

I made the background blocker shape semi-transparent in the final slide so you could see what's happening to the "guts".

Hope this helps:)

Rebecca Fleisch Cordeiro

Hey Steve,

Wow. Your directions are perfect and your example was great. Thanks for the additional explanatory slides.

And, I was able to recreate successfully with a similar but different drag/drop scenario.

But (apologies) I don't understand how this gets at Brenda's request, which I'm pasting here:

To pass this 'quiz', I require that at least 8 out of 10 of the items be dropped correctly.  They don't ALL have to be correct (which is what the default Storyline Drag and drop interaction scoring wants).

...

my problem is the Results slide...keeps sending me to the Fail layer if I have 8 or 9 correct due to the "Results.ScorePoints" variable = 0 ; it should go to the Success layer and that's why I'm trying the java script idea to set that Results.ScorePoints variable  (if 10 out of 10 are correct, everything works fine).

This is set up so the True button is selected if all of the draggable items are dropped correctly. And False if any are incorrect Is there a way to set it up so that, for example in your example 4 or 5 of the 6 are dropped correctly? And, without knowing which 4 or 5 the Learner is going to select?

Steve Flowers

Yep. She's already got the triggers setup to do that, just needed a way to report the points correctly to the results slide. For example, if I wanted to run a points system -- there are a few ways to do that using this example.

The most reliable would be setting up a variable for each shape. When a shape is dropped on the right spot, set the variable to 1 when it's set on the wrong spot, set it to zero. On each drop, calculate the total of all of the shape variables. If the value is higher than the minimum value, set the guts to true. If not, set it to false.

Brenda Heilman

Steve Flowers said:

Yep. She's already got the triggers setup to do that, just needed a way to report the points correctly to the results slide. For example, if I wanted to run a points system -- there are a few ways to do that using this example.

The most reliable would be setting up a variable for each shape. When a shape is dropped on the right spot, set the variable to 1 when it's set on the wrong spot, set it to zero. On each drop, calculate the total of all of the shape variables. If the value is higher than the minimum value, set the guts to true. If not, set it to false.

Yep, you are sooo right...this worked perfectly Steve.  You ROCK!
Pas Krak

If you want to know  how many points have been scored in a drag & drop slide, it would be an idea to use the multiple choice as hidden, rather than true/false.

Have a variable which is incremented for each correct d&D, Based on the number of correct answers , change the state of the (hidden) multiple choice buttons - which incidentally allows partial marking! This gets transferred to "Results.ScorePoints"  when the quiz is submitted.

For e.g.: if  2 D&D are correct change the state of MC to button 2 - to which you can allot 2 points.

I hope I am making sense.

Steve Flowers

Hi Pas - 

Yes! Definitely. And now that you can have choices count against the score, it makes even more sense to do this. I've used hidden T/F for activities that aren't granular and multiple choice for a little more granular tracking, reserving multiple select for tracking to the step or choice within the activity.

Saul  Jacobs

Hi Steve

On a similar line, I'm trying to report multiple text entries on one slide. I've added triggers to adjust a  "score" variable I've created using a condition (if text entry matches, than add "1" to value. I then want to the "result.score.points" variable to be set to my "score" variable so that it is reported as the score to the LMS. But it won't allow me to assign a variable to "results.score.points". 

A simple "fill in the word" quiz will not do, as we need to add 4 entries on each slide and report a score for each entry.

Hope I've been able to explain my problem.

 

Thanks

Saul

Michael Hinze
Saul Jacobs

Hi Steve

On a similar line, I'm trying to report multiple text entries on one slide. I've added triggers to adjust a  "score" variable I've created using a condition (if text entry matches, than add "1" to value. I then want to the "result.score.points" variable to be set to my "score" variable so that it is reported as the score to the LMS. But it won't allow me to assign a variable to "results.score.points". 

A simple "fill in the word" quiz will not do, as we need to add 4 entries on each slide and report a score for each entry.

Hope I've been able to explain my problem.

 

Thanks

Saul

The built-in Results variables are read-only and cannot be changed.

Steve Flowers

The alternative to recording custom scores is directly accessing the SCORM functions through a JavaScript trigger. James explains one way to do this here:

https://elearningenhanced.com/blog/2012/09/13/update-storyline-courses-status-lms-javascript

You'd grab your custom score and pass this through the JS trigger. Whenever I do this, I set Storyline's tracking to total slides visited and add a slide that cannot be reached by the user. This ensures SL's tracking won't inadvertently overwrite the intended function.

Saul  Jacobs

Hi Steve

Thanks for this, sounds like a great option.

So if I understand you correctly, using the JS script, a LMS like Moodle would accept my custom score and report it as the standard score?

If I look at Jame's script where would I add my custom score variable?

/get LMS API
var lmsAPI = parent;
//set score; the first number is the score
lmsAPI.SetScore(90, 100, 0);

Alex Y

Thanks so much Steve!  By combining your solution for one issue here and another tutorial from Wim here I was able to get exactly what I needed.  A multi-drag and drop with multi-correct targets interaction as a graded question.  You folks rock!

Only real down-side is I can't figure out how to make the drop object snap to the centre of the drop target since it's not really a drop target and we're just faking out the True/False interaction...unless of course i'm missing something obvious.  Any pointers?

**UPDATE**

Shortly after posting my update I figured it out, looks like I can set the drag and drop preferences by right clicking on the intended target.  Thanks again folks!

James Bonney

Hi, can you help?

This is what my JS looks like..."TotalTokens" is the number variable that I'm using to add the user score that i want to send to my Moodle LMS.

But it didn't work, it still sent through the normal scoring method. Have I done the JS right?

var player=GetPlayer();
var customScore=player.GetVar("TotalTokens");

//get LMS API
var lmsAPI = parent;
//set score; the first number is the score
lmsAPI.SetScore("TotalTokens", 100, 0);

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