Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: Global variable question in tutorial  (Read 4266 times)

0 Members and 1 Guest are viewing this topic.

Magnolia

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 30
    • View Profile
Global variable question in tutorial
« 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.
Logged

Azrael

  • Regular poster
  • ***
  • Karma: 9
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • View Profile
    • Mad Orange
Re: Global variable question in tutorial
« Reply #1 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".
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Global variable question in tutorial
« Reply #2 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.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Magnolia

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 30
    • View Profile
Re: Global variable question in tutorial
« Reply #3 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"?
Logged

2.0

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 217
    • View Profile
Re: Global variable question in tutorial
« Reply #4 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 :)
Logged

Azrael

  • Regular poster
  • ***
  • Karma: 9
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • View Profile
    • Mad Orange
Re: Global variable question in tutorial
« Reply #5 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)
Logged

Magnolia

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 30
    • View Profile
Re: Global variable question in tutorial
« Reply #6 on: May 27, 2013, 10:01:47 PM »

Ok, got it.
Logged
 

Page created in 0.045 seconds with 25 queries.