Changing something in another room

Started by metalmario991, Sun 22/02/2015 19:20:38

Previous topic - Next topic

metalmario991

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?

Matti

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.

Slasher

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)


RetroJay

#4
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
import bool Button_Pressed;

Then in Global script at the top type
Code: ags
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
Button_Pressed=true;

In the room with you door put inside room load
Code: ags
if (Button_Pressed==true){
//door is open script//
}
else {
if (Button_Pressed==false){
//door stays shut script//
}


Hope this helps.

RetroJay


Cassiebsg

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... ;)
There are those who believe that life here began out there...

RetroJay

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. ;)

Mouth for war

Strazers "other room module" comes to mind :)
mass genocide is the most exhausting activity one can engage in, next to soccer

SMF spam blocked by CleanTalk