Forum Discussion

Will_Findlay's avatar
Will_Findlay
Community Member
6 years ago

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_Findlay's avatar
    Will_Findlay
    Community Member

    I found a workaround - create a trigger that assigns the built-in variable to a user variable.

  • Will_Findlay's avatar
    Will_Findlay
    Community 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!

  • Will_Findlay's avatar
    Will_Findlay
    Community 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_Findlay's avatar
    Will_Findlay
    Community 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. :-)

  • YaachYaach's avatar
    YaachYaach
    Community Member

    Where can I get the list of built-in variables you mentioned? I dont see Menu.SlideTitle

  • Hi, Yaach.

    You can access the built-in variables through the variables manager:

    Windows 10 (1) 2021-12-13 at 10.28.44 AM

    I hope this helps!

  • AimeeWoodward's avatar
    AimeeWoodward
    Community 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.