Page 1 of 1

Savegames and boolean variables

Posted: 06 Apr 2012, 07:45
by NoQ
Just noticed a case when the following code

Code: Select all

			debug(me,someBooleanVariable);
			if (someBooleanVariable==false) {
				debug(me,"x",someBooleanVariable);
			}
			if (someBooleanVariable!=false) {
				debug(me,"y",someBooleanVariable);
			}
prints

Code: Select all

2 false
2 x false
before saving/loading, but prints

Code: Select all

2 false
2 y false
:shock: :shock: after saving/loading O_o (that is, the variable isn't equal to false, but it prints false when debugging it)

Re: Savegames and boolean variables

Posted: 06 Apr 2012, 23:28
by iap
Maybe because it is saved as a string "false" witch is Boolean true (like any other not empty string).

Re: Savegames and boolean variables

Posted: 07 Apr 2012, 09:07
by Emdek
And what returns this code?

Code: Select all

         debug(me,someBooleanVariable);
         if (!someBooleanVariable) {
            debug(me,"x",someBooleanVariable);
         }
         if (someBooleanVariable) {
            debug(me,"y",someBooleanVariable);
         }

Re: Savegames and boolean variables

Posted: 08 Apr 2012, 06:55
by aubergine
Some good references for anyone working with JS or the JS API:

Funny video: https://www.destroyallsoftware.com/talks/wat

Explanation of apparent weirdness shown in vid above: http://stackoverflow.com/a/9033306

Some great blog posts:

* http://javascriptweblog.wordpress.com/2 ... avascript/
* http://javascriptweblog.wordpress.com/2 ... rimitives/