Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: metalmario991 on Sun 22/02/2015 19:20:38

Title: Changing something in another room
Post by: metalmario991 on Sun 22/02/2015 19:20:38
In my game you need to press a button to open a door in another room but when I put that in the script and start playtesting it says the object is undefined because it is not in that room. How do I make something in one room affect something in another?
Title: Re: Changing something in another room
Post by: Matti on Sun 22/02/2015 19:26:50
Use a global variable e.g bool door_open;

In one room, set door_open = true when the player presses the button.

In the other room change the door object according to that variable.
Title: Re: Changing something in another room
Post by: Slasher on Sun 22/02/2015 19:29:02
You could make a global boolean and turn to true when button is pressed. When you enter the next room you need to, in it's room load, put a condition if the boolean is true and if it is true it will affect object in that room.

Like Matti said, who just beat me (nod)
Title: Re: Changing something in another room
Post by: metalmario991 on Sun 22/02/2015 19:56:18
Thank you. That worked fine.
Title: Re: Changing something in another room
Post by: RetroJay on Sun 22/02/2015 20:10:52
Hi metalmario991.

Yes. Boolean.
I am at work typing this so it's off the top of my head... but...
In the script header type
Code (ags) Select
import bool Button_Pressed;
Then in Global script at the top type
Code (ags) Select
bool Button_Pressed;
export Button_Pressed;

That's the bool set up.

Now, in the script you have for the button put this
Code (ags) Select
Button_Pressed=true;
In the room with you door put inside room load
Code (ags) Select
if (Button_Pressed==true){
//door is open script//
}
else {
if (Button_Pressed==false){
//door stays shut script//
}


Hope this helps.
Title: Re: Changing something in another room
Post by: RetroJay on Sun 22/02/2015 20:13:49
Bugger too late.(laugh)

Glad it worked.;-D
Title: Re: Changing something in another room
Post by: Cassiebsg on Sun 22/02/2015 20:25:28
Ahm... RetroJay, you don't need all that import/export stuff, all you need is to define a Global Variable (you find it on your project tree) and create the variable there with an initial value. Then all you need to do is set it up in the script to change that value, and then the if/else condition to check for the change... ;)
Title: Re: Changing something in another room
Post by: RetroJay on Sun 22/02/2015 20:48:44
Hi Cassiebsg.

Yes of course.
However I personally prefer to have them in global script.
That way I can write notes beside them and keep better track of what is doing what.
It's just the way I prefer to do it though. ;)
Title: Re: Changing something in another room
Post by: Mouth for war on Sun 22/02/2015 22:51:42
Strazers "other room module" comes to mind :)