JavaScript and boolean variables

Jun 10, 2015

I am trying to pass boolean variables (true/false) to and from storyline player (Flash and HTML5).

But is seems it only sends strings ("true" of "false"), and not actual boolean values.  Thus send false is interprited by the player as a string, and evalutates to a true value.

Or am I doing something worng...

I have tried putting the valus in quotes on the javascript side, but the Articulate player seem inconsistent. Have also tried sending 1 and 0.


My code:


var player=GetPlayer();

var numOfSlides = player.GetVar("numberOfSlides");
var slideViewed = false;

for (var i=1; i <= numOfSlides; i++) {
  slideViewed  = player.GetVar("s" + i);
//  alert (slideViewed);

   if (slideViewed == "false") {
// alert("Not  done" + i );
      player.SetVar("allSlidesViewed", fasle);
   else {
//       alert(" all Done" + i);
       player.SetVar("allSlidesViewed", true);




6 Replies
Morten Tvedten

Yes, I did look at the Best Pratice page, but that does not cover boolean variables, and how they are passed.

Yes, Jerson, that misspelled "false" was just in this post, as i did some tweaking before I sent it in a hurry. :-)

The Storyline variable i set as a True/False.

I had to put quotes around "false" in the if-statemenet for it to work. If I wrote it like I naturally would:

slideViewed  = player.GetVar("s1"); 

if (slideViewed == false) {...}

- the stament was alway true. That suggested to me that the value inside slideViewed is not a boolean value of false, like it should be, but a text string with the text "false". 

So the question remains; If you get, or set, a boolean value from a variable inside the SL-player, do you get a proper boolen value, or just a text string with "true" or "false"?

Also the other way around, when passing a value to the player, I would natuarlly use the boolean value. eg. 

player.SetVar("allSlidesViewed", fasle);

Will this be properly stored in the Storyline True/False variable? It seems a bit inconsitent between Flash and HTML5 player...

Nigel Kirkby

Hi Morten

I was having to work with booleans in Javascript today and came across this thread. It does appear that storyline booleans when used in javascript equate to a string with "true" or "false" as the value, as I couldn't get a simple if (var == true) to work (or rather I could but I couldn't get the else to work as intended), but could with a if (var == "true"). Hope this helps anyone else.

This discussion is closed. You can start a new discussion or contact Articulate Support.