Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Racoon on Mon 25/11/2019 19:21:23

Title: Trying to make events in one room influence another room [SOLVED]
Post by: Racoon on Mon 25/11/2019 19:21:23
Hey,

I am at a dead end again. I would like the visibility of an object1 in room1 to influence the visibility of object2 in room2 with if/else. But since object1 is not in room2, it wont be recognized in the script of room2.

How can it work?

Thanks!
Title: Re: Trying to make events in one room influence another room
Post by: Slasher on Mon 25/11/2019 19:31:39
You can use a variable like a boolean.

Change to false/true depending on the object visibility in room one.

In room two set object if boolean true else set if false

Title: Re: Trying to make events in one room influence another room
Post by: Crimson Wizard on Mon 25/11/2019 19:56:54
To elaborate a little on what slasher said, the only way is to save other room's state in a variable (or multiple variables, depending on how much you need to change), and then assign new state to objects in that room's "Enter room before fade-in" event.

The variables have to be global, because room variables are only accessible within same room too.

For example, create a global variable of type "bool" called "Room2_MyObject_Visible".
Then in room 1 script you do
Code (ags) Select

Room2_MyObject_Visible= true; // or false

And in room 2 you create a function for "Enter room before fade-in" in which you do
Code (ags) Select

oMyObject.Visible = Room2_MyObject_Visible;
Title: Re: Trying to make events in one room influence another room
Post by: eri0o on Mon 25/11/2019 19:59:50
The state can also be stored for later consumption on room leave event
Title: Re: Trying to make events in one room influence another room
Post by: Crimson Wizard on Mon 25/11/2019 20:07:45
Quote from: eri0o on Mon 25/11/2019 19:59:50
The state can also be stored for later consumption on room leave event

Yes, right, this is actually important, if you want the variable to be consistent at all times, and in case you change object visibility in room 2 script as well.

The general logic is this:

* you have a real room's state, only loaded when room is on;
* you have a set of variables that store room's state (maybe partially, like only one object's visibility).

* in "Before fade-in" event you copy state from variables to room objects
* in "Leave room" event you copy state from room objects to variables.

this way everything stays in sync and you may get and change this information outside of the room.
Title: Re: Trying to make events in one room influence another room
Post by: Racoon on Mon 25/11/2019 21:16:24
Thanks for that quick support! It worked out just fine. Special thanks to Crimson Wizard for that detailed example  :)