Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Bandersnatch on Wed 11/09/2013 17:09:43

Title: Determining whether a door is open or closed...
Post by: Bandersnatch on Wed 11/09/2013 17:09:43
Hi all,

I know this will sound really amateur, but how do I make my game determine whether a door is open or closed and change the player character's actions accordingly?

The closed door is set as an object with a hotspot behind it for the open doorway (initially disabled). I can have my character open the door, but when I want her to close it, she still says "It's already closed". I have no idea what conditions/parameters/variables/states to change in order to make the door work properly...:undecided:
Title: Re: Determining whether a door is open or closed...
Post by: Bandersnatch on Wed 11/09/2013 17:19:58
Never mind, found a way. I think.
Title: Re: Determining whether a door is open or closed...
Post by: Khris on Wed 11/09/2013 17:23:45
Just a quick comment: if you change the state of the door object, say by turning it invisible or changing its sprite, you can use the same property to determine the door's state.
The other way is to put "bool door_open;" at the top of the room script. You can now change the bool's value to true and back to false or test its current value at any point in the room script.
Title: Re: Determining whether a door is open or closed...
Post by: Bandersnatch on Wed 11/09/2013 21:00:59
I've never used a boolean (spelling?) before so I'm not entirely sure how they work. Seriously, I have such good intentions but my tiny brain struggles with even the most basic of coding. How would a piece of script look using a bool command for a door?
Title: Re: Determining whether a door is open or closed...
Post by: Khris on Wed 11/09/2013 22:27:26
A boolean is a variable that can either be true or false.

Here's an example script:
Code (ags) Select
bool door_open;  // initial value: false

// player examines door
function oDoor_Look() {
  if (door_open) player.Say("I can see the kitchen.");
  else player.Say("This door leads to the kitchen.");
}

function oDoor_Interact() {
  if (door_open) oDoor.Graphic = CLOSED_DOOR_SPRITE;
  else oDoor.Graphic = OPEN_DOOR_SPRITE;
  door_open = !door_open;  // ! is the not operator, it'll turn true into false and vice versa
}
Title: Re: Determining whether a door is open or closed...
Post by: Stupot on Thu 12/09/2013 10:05:45
Quote from: Khris on Wed 11/09/2013 22:27:26door_open = !door_open;  // ! is the not operator, it'll turn true into false and vice versa
Cool tip!
Title: Re: Determining whether a door is open or closed...
Post by: Adeel on Thu 12/09/2013 11:09:06
Quote from: Stupot+ on Thu 12/09/2013 10:05:45
Quote from: Khris on Wed 11/09/2013 22:27:26door_open = !door_open;  // ! is the not operator, it'll turn true into false and vice versa
Cool tip!

Indeed! (nod)