Forum Discussion
Can Javascript access built in variables?
I'm trying to use this code in a trigger but it is just alerting with "null":
var player = GetPlayer();
alert(player.GetVar("Menu.SlideTitle"));
Am I doing something wrong, or are Built-In Variables not yet accessible via javascript?
9 Replies
- Will_FindlayCommunity Member
I found a workaround - create a trigger that assigns the built-in variable to a user variable.
- NancyWoinoskiSuper Hero
just curious, are you trying to create a custom menu?
- Will_FindlayCommunity Member
That's a great use I hadn't thought of!
I was actually doing this so I could put an Execute Javascript trigger on a Slide Master that would send the name of the slide to a Learning Record Store using xAPI. It actually works quite well and makes it so you only have to insert the javascript code once!
- NancyWoinoskiSuper Hero
Nice!
- Will_FindlayCommunity Member
Here is more detail (per request from someone via email:)
I set up a trigger on my slide like this:
And then an Execute Javascript Trigger after it that contains this code:
/*Statement*/
var slideTitleSL = player.GetVar("slideTitle");
console.log(slideTitleSL); - Will_FindlayCommunity Member
Oh yes. Good call Matthew! And you don't really need that console.log statement. But I like to throw those in there frequently to make it easier to debug when viewing the Javascript console in Chrome. :-)
- YaachYaachCommunity Member
Where can I get the list of built-in variables you mentioned? I dont see Menu.SlideTitle
- MariaCSStaff
Hi, Yaach.
You can access the built-in variables through the variables manager:
I hope this helps!
- AimeeWoodwardCommunity Member
Hi. I am using the build-in variable Quiz2.ScorePercent. When I pull it into the jsPDF it brings a value of null. I have referenced the variable on slides and it is bringing up a number, so I am not sure why it is bring up null in this instance.