Forum Discussion
MathNotermans-9
3 years agoCommunity Member
Global scope for Javascript variables in Storyline
As Storyline publishes all code and variables to separate functions in the user.js file the scope for individual variables is local. The solution i show here creates a global scope for functions and...
Jürgen_Schoene_
3 years agoCommunity Member
if you wan't to use small solutions for global variables in javascript - use window-variables (storyline is technical a single-page application)
https://javascript.info/global-object
example
javascript trigger 1:
function hallo(){
window.myText = "hallo";
}
javascript trigger 2:
function printHallo(){
console.log( window.myText );
}
normaly window variables are not used*, the normal javascript would be
var myText;
function hallo(){
myText = "hallo";
}
function printHallo(){
console.log( myText );
}
the result is the same, but this it is not possible in a trigger javascript
Jürgen
* as a developer you should not use such things - global variables are nasty. If you are not careful, they can cause big problems. Normally you encapsulate variables.