Savegames and boolean variables

For AI and campaign script related discussions and questions
Post Reply
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Savegames and boolean variables

Post 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)
iap
Trained
Trained
Posts: 244
Joined: 26 Sep 2009, 16:08

Re: Savegames and boolean variables

Post by iap »

Maybe because it is saved as a string "false" witch is Boolean true (like any other not empty string).
User avatar
Emdek
Regular
Regular
Posts: 1329
Joined: 24 Jan 2010, 13:14
Location: Poland
Contact:

Re: Savegames and boolean variables

Post 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);
         }
Nadszedł już czas, najwyższy czas, nienawiść zniszczyć w sobie.
The time has come, the high time, to destroy hatred in oneself.


Beware! Mad Qt Evangelist.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Savegames and boolean variables

Post 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/
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Post Reply