Forum Discussion

ScottWeiner-152's avatar
ScottWeiner-152
Community Member
3 months ago

Passing Objects between JS Triggers

I can't seem to pass an object between triggers in Javascript.  In Trigger A, I have a

let myTable;

statement on the first line.  Then I'm using Tabulator to create a myTable.  In Trigger B, which might run on a button click or at a certain time (say after 10 seconds), I want to reference myTable to turn a row of that table a different color.  I've tried async/await, but it doesn't seem to work.  Is it possible to update myTable in a separate javascript trigger or is that not possible in SL?  I'm pretty new to JS and integrating into Storyline.  Any help would be greatly appreciated.  Thanks!

  • Scope issue. Each trigger has its own scope. Search for that on my posts and you will find sample to fix this.

  • For example this one: https://community.articulate.com/discussions/discuss/global-scope-for-javascript-variables-in-storyline/1060627

  • Some other user asked me for tables using Tabulator in Storyline too. Im gonna make a tutorial on that when im back home. That will be after the weekend.

  • Math's approach has a lot of great uses. As someone in his post mentions, window globals are also easy, but preferentially avoided. If you want something simple and straightforward, you can also assign references to Storyline text variables. For example:

    // In one trigger script...
    let myTable;
    
    //... do some coding stuff with myTable
    
    // make sure you have already created a SL text variable called myTable
    GetPlayer().SetVar("myTable", myTable); 
    
    //-------------------------------------------------------------------------------------------------
    
    // In another trigger script...
    myTable = GetPlayer().GetVar("myTable");
    
    //... do stuff with myTable as you normally would

     

    • MathNotermans-9's avatar
      MathNotermans-9
      Community Member

      Nathaniel 😉, we should start a company.

       

      Nath+Math elearning tricks 😄

  • Nath's approach is good in many cases. However using it with Tabulator is complex. My main approach is using a generic_javascript file in which i define functions. All refer to the same file an all variables needed are also in it. So on any trigger on any slide i then can call a function from that file, inclusief Tabulators specific ones.