impossible to set a variable to (blank) using JavaScript from an external source?
Nov 01, 2018
I am having problems setting some variables outside of Storline 360 and reading them in so they can be identified.
Boolean variables and number variables work fine.
But it is text variables - principally when a text variable is set to be null or blank...
So logic that depends on a Storyline text variable being (blank) seems not to work...it works if the text contains a string but not when reading in a blank or null...
The issue we had with the “is (blank)” logic is when doing:
window.GetPlayer().SetVar('C1Q1', null);
window.GetPlayer().GetVar('C1Q1');
null
window.GetPlayer().SetVar('C1Q1', '');
window.GetPlayer().GetVar('C1Q1');
""
The is (blank) logic doesn’t seem to treat empty strings or nulls as blank, so we think it’s impossible to set a variable to (blank) using JavaScript, despite us verifying the variable was set correctly.
Help please very much appreciated...
Chris
9 Replies
I think storyline treats null and blank as two separate "values" I often find that numeric values although having a initial state of 0 are null until the value is set. Similar with text fields, no solution I have had similar things happen.
Hi Matthew,
I need a flag set from outside - a variable that either contains text or is blank when the data are read in and out. Then the logic will either select or deselect a checkbox. Checking if the variable is not blank works, but if the variable is required to be empty, blank, null or effectively contain nothing then Storyline does not understand the contents/lack of content. It's as if 'blank' is not the same in Storyline as an empty text variable. We have verified that the variable is being read in correctly but not being interpreted correctly.
Hello, I don't know if it's an acceptable solution, but did you try to assign a whitespace character to this variable ?
Hi,
Thanks - I am unsure what you mean exactly?
Chris
Have you tried declaring a variable in JavaScript without assigning a value and then setting your SL variable = to the empty JS one? Something like:
var s = new String();
window.GetPlayer().SetVar('C1Q1', s);
OK I will try that - thanks
@Owen your method works, but as a JavaScript novice the syntax:
var string = "";
window.GetPlayer().SetVar(string);
made more sense to me. Just throwing this out there in case it's useful to other novices like myself.
There are absolutely multiple ways to do this and the method you proposed does create a variable as a string. Specifically, it creates a string literal.
Normally, JavaScript strings are primitive values, created from literals:
let x = "John";
But strings can also be defined as objects with the keyword new:
let y = new String("John");
Interestingly enough, these 2 things are not equal.
If you tested to see if the values of x and y above were the same (x==y) it would return "true".
However, if you tested to see if the value and the type were the same (x===y) it would return false.
For this specific question, either will do, but in the spirit of moving you from Novice forward, just know that there is a difference and how you declare a variable can matter.
Owen, that's good to know. Thank you! That's a little different than the languages I've used in the past.