Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: amuse on Sun 14/02/2010 14:42:15

Title: Problem with Bool and changing rooms
Post by: amuse on Sun 14/02/2010 14:42:15
Hi all,

I want to have conditions that things will happen only if a player has done a certain thing.

looking into the manual and reading here I finally made this which almost work. The code fails when I change the bool from an other room

My code is seperated in 3 parts

in the  GlobalScript.ash I have

bool my = false;

in the first room I have

// room script file


function hHotspot1_AnyClick()
{
my = true;
}

function hHotspot2_AnyClick()
{
  if (my == true){
  Display("this is true");
  Display("very true");
}
 
  else if (my == false){
   Display("this is false");
   Display("this is sooo false");
  }
}

function hHotspot3_AnyClick()
{
  cEgo.ChangeRoom(2);
 
}
So from that first room I am able to set the bool to true

now room number 2


function hHotspot1_AnyClick()
{
cEgo.ChangeRoom(1);
}


function hHotspot2_Look()
{
my = false;
Display("now set to false");

}

Now in room two I set the bool the false and go back to the first room. I click on hotspot2 and saddly it's still set to true.

What am I doing wrong.

amuse
Title: Re: Problem with Bool and changing rooms
Post by: Calin Leafshade on Sun 14/02/2010 14:48:01
You need to use global variables if they are for several different rooms.

look for the "global variables" tab down the right hand side.

you CAN define it in the global script but you need to "export" the variable right at the end of the script.

look up the 'export' keyword in the manual
Title: Re: Problem with Bool and changing rooms
Post by: Gilbert on Sun 14/02/2010 14:48:46
By declaring the boolean variable in GlobalScript.ash you are declaring such a variable in every room, each local to the respective room.

Instead, to make a real global variable, you have to put it in GlobalScript.asc and export it, then import it in the script header for all the rooms to access it.

So, in GlobalScript.asc :
bool my = false;
export my;


Then, in GlobalScript.ash :
import bool my;
Title: Re: Problem with Bool and changing rooms
Post by: amuse on Sun 14/02/2010 14:54:43
So simple and yet...:)

Thanks a lot guys! works like a charm now!

amuse