Getting Custom Variable using player.GetVar in SL 360
Jan 17, 2020
For years I have been getting a custom variable in SL2, but now I am trying this in SL360 and it is not working.
The javascript is:
var player = GetPlayer();
var myQuestionID = player.GetVar("myQuestionID");
I have seen a lot of discussion around the GetPlayer and LMS object in SL360, but this article seems to suggest that it is working as shown above. I have also tried some suggestions I have seen like window.GetPlayer(), parent.GetPlayer(), etc., but those threads are old and have a lot of different opinions.
Is there a definitive answer to this now? Should I be able to retrieve my custom variable using the javascript trigger above?
Thanks.
8 Replies
Code looks good to me. How/where are you publishing to test?
Saving as a SCORM 2004 package and uploading to our own LMS system (same as our SL2 output has been using).
I think now that it is going wrong in the next step of my code:
lmsAPI.g_myQuestionID = myQuestionID;
Perhaps the difference is finding the lmsAPI object?
Yes, that was it. See the solution here.
That's the tricky thing in JS... often when one part of the script breaks, it breaks the whole thing.
Hey, this is my experience as well. After many hours of troubleshooting, we discovered that the quotation marks matter. I copied code from another place and pasted it into my javascript. These were different than the ones that I typed. One I retyped the quotes in storyline javascript area, my code worked. This would be a nice enhancement for Storyline to recognize all quotation marks.
It would be nice, however, the quotation mark functionality is actually part of the JavaScript programming language. Storyline lets you run JS, but it isn't designed to be a programming tool.
Yes, totally understand. However, when you copy and paste, it would be a nice feature if Storyline environment viewed/converted them all as the same type of quotation marks. Just sharing my experience. Thanks Owen!