Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: Magnolia on May 27, 2013, 05:11:04 AM

Title: Global variable question in tutorial
Post by: Magnolia on May 27, 2013, 05:11:04 AM
This is from the very last part of chapter 3 in the tutorial.  In the exit script:

on "ActorEntry"
{
   var door = Scene.GetNode("Door");
   Game.Interactive = false;
   global doorClicked;
   if (!doorClicked)
   {   
      actor.Talk("I don't want to return to my flat before I am sure I can't enter the warehouse!");
   }
   else
   {   
       Scene.DetachScript("scenes\warehouse\scr\bomb.script");
       actor.Talk("Phew. that was close");
      Game.ChangeScene("scenes\room\room.scene");
   }
   Game.Interactive = true;

I understand the concept of the script.  I don't understand what this line really means:

global doorClicked;
if (!doorClicked)

The bomb script and the door script set the global variable to either true or false. So I am assuming "global doorClicked;" calls the global variable and "if (!doorClicked)" is checking which value the global is.  But does this read:  if not equal the global variable?  Because that doesn't make sense to me.
Title: Re: Global variable question in tutorial
Post by: Azrael on May 27, 2013, 06:24:08 AM
Code: WME Script
  1. if (!doorClicked)

It's the same than writing:

Code: WME Script
  1. if (doorClicked != true)

So probably there is one script on the door that once the player have clicked no it will set the global doorClicked to "true".
Title: Re: Global variable question in tutorial
Post by: Mnemonic on May 27, 2013, 07:08:26 AM
Global variables exist independently on scripts.

So by the line:

Code: WME Script
  1. global doorClicked;
  2.  

the script is merely saying "I want to access the value of a global variable called doorClicked". So after this line, the doorClicked variable in a script contains whatever value the global contained before (or null if no other script set the variable before).

In other words, global variables are the way of sharing values between multiple scripts.
Title: Re: Global variable question in tutorial
Post by: Magnolia on May 27, 2013, 06:52:51 PM
Ok, good.

So  with " if (!doorClicked)", do you mean anytime there is a "!" in front of a global var, it always means the "global var ne true"?
Title: Re: Global variable question in tutorial
Post by: 2.0 on May 27, 2013, 07:06:35 PM
Ok, good.

So  with " if (!doorClicked)", do you mean anytime there is a "!" in front of a global var, it always means the "global var ne true"?

Yeah, and in front of any var :)
Title: Re: Global variable question in tutorial
Post by: Azrael on May 27, 2013, 07:20:43 PM
And in the same way without the !:

Code: WME Script
  1. if (doorClicked)

is the same than:

Code: WME Script
  1. if (doorClicked == true)
Title: Re: Global variable question in tutorial
Post by: Magnolia on May 27, 2013, 10:01:47 PM
Ok, got it.