Forum Discussion
Global scope for Javascript variables in Storyline
For anyone reading this in the future : In addition to what Math spotted (the "go to slide" instruction that prevents previous javascript call) many of my difficulties here were because I had several errors in my script that immediatly disables all javascript in the project. The slightest missing ";" at an end of line can cause this.
In my case, I used also "let" declaration for a temp variable I wanted to declare & initialize several times in the same javascript call. At the very moment a 2nd "let" line for the same variable appeared in my script, nothing worked anymore.
I didn't yet sort the "Storyline goes too quick to the next slide" problem properly : actually I stop the chronology of the current slide, and when the user clicks "next" button I call my js fucntions and let the slide carry on : it ends 1 second later, with automatic go to next slide. And this seems enough for letting js call to be done.
I have a last question @Math : can your solution work with a 4D array as mine ? I would like to try to initialize my array from within a javascript inside my storyline project rather than from globaScript.js file, that would prevent the WebObjectURL value to change each time the content of my array has changed.
- MathNotermans-99 months agoCommunity Member
Basically you donot need to use the globalScript approach. And yes it works fine with a multidimensional array ( 4D array is a multidimensional array with 4 dimensions ).
You can even use pure Javascript Storyline triggers and set a Storyline variable to hold your array. - MathNotermans-99 months agoCommunity Member
Just made a sample showing proper workflow for creating multidimensional arrays and gettting the data from it.
https://360.articulate.com/review/content/7c1e0e02-77c8-4bb5-a632-21c21d10f7f3/review
Clicking the create multi array button creates a 3-dimensional array.
You can change the inputs for the depth of the array and the 2 inputs from 0-2 showing a value in the appropriate cell.
Clicking show value from array shows the appropriate value from the multidimensional array.
In fact clicking either button will create that multidimensional array from the variable showing... 'cows,horse,monkey,grass...' etc. As this variable now is only 9 items long, changing the dimensions of the multiarray to more then 3 will result in getting 'null' as the cells will be empty.
But basically this has all to create your own multidimensional arrays.
Kind regards,
Math