Problem with Bool and changing rooms

Started by amuse, Sun 14/02/2010 14:42:15

Previous topic - Next topic

amuse

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

Calin Leafshade

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

Gilbert

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 :
Code: ags
bool my = false;
export my;


Then, in GlobalScript.ash :
Code: ags
import bool my;


amuse

So simple and yet...:)

Thanks a lot guys! works like a charm now!

amuse

SMF spam blocked by CleanTalk