Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: beenf on Tue 05/04/2011 16:51:56

Title: SOLVED Having problem with walkable areas :(
Post by: beenf on Tue 05/04/2011 16:51:56
When I go through my door when it's closed I can't go through. (WalkableArea is removed)
Then I give a character a item and the door will open.(RestoreWalkablearea)
Then I go through the door and appear in another room.
Now the problem is:
If I go back to previous room the door still looks open, but the walkable area in door is removed, but I opened it before.
My code looks like this:

function room_Load()

{
 RemoveWalkableArea(2);
 }

function cVamp_UseInv()
{
 if (player.ActiveInventory == iklaasjaveri) {
   cVamp.Say("Thank you for the blood.");
   cVamp.Say("How can I repay you?");
   player.Say("Let me through the door, maybe?");
   cVamp.Say("Ohh, alright. You deserve it.");
   oDoorOpen.Visible=false;
   oDoorClose.Visible=true;
   player.LoseInventory(iklaasjaveri);
   RestoreWalkableArea(2);
   
 }
}

These codes are in the same room script where the doors and character is. Hope someone finds what I did wrong
Title: Re: Having problem with walkable areas :(
Post by: TomatoesInTheHead on Tue 05/04/2011 17:35:57
The room_Load function is executed when entering (i.e. loading) the room, so the RemoveWalkableArea function is executed every time you re-enter it.

I see this issue was unfortunately not covered in the tutorial video you mentioned in the other thread.

You can use a flag in the room_Load function to determine whether the walkable area has to be removed or not. For example, here you can probably use oDoorOpen.Visible or oDoorClose.Visible in a condition.

btw,
1) wouldn't one of the door objects suffice? If you draw an open door in the background and put a closed door object on it, you can open/close it only with showing/hading this one object.
2) your naming for the objects doesn't seem too logical to me. If the vampire opens the door, you make the closed door (oDoorClose) visible and the open door (oDoorOpen) invisible?
Title: Re: Having problem with walkable areas :(
Post by: beenf on Tue 05/04/2011 20:57:21
yeh the odooropen/odoorclose thing was mixed :P, but that wasn't the case

How do I use them in condition? Can you maybe plz give me a code?
Title: Re: Having problem with walkable areas :(
Post by: TomatoesInTheHead on Tue 05/04/2011 21:32:35
Since you already use the condition
if (player.ActiveInventory == iklaasjaveri) { ... }
in the other function, you should know what conditions look like (if not, read through any code you copy from somewhere to understand how and why it works, and consult the manual).
Now you want to know if the door is closed, so your condition is "oDoorClose.Visible == true" ("== true" may be omitted).
And in the {} (which may also be omitted if they contain only one line of code) comes what you want to happen on each room load when the door is still closed: that the walkable area is removed.
Title: Re: Having problem with walkable areas :(
Post by: beenf on Wed 06/04/2011 05:46:11
How do I use flag?
Title: Re: Having problem with walkable areas :(
Post by: TomatoesInTheHead on Wed 06/04/2011 09:58:44
How to use a flag: You uncoil it, then wave it over your head while jumping up and down until someone notices you.


What I called "flag" in the above post is just a boolean/binary variable/property/field/value, i.e. one that may be true or false, just like, as I said, oDoorClose.Visible. There's nothing more on how to use it other than what I already said.
Title: Re: Having problem with walkable areas :(
Post by: Creator on Wed 06/04/2011 10:42:08
To expand a little on what TomatosInTheHead said, you could use a boolean (we'll call it "isDoorOpen").


bool isDoorOpen = false; //our variable (or flag) for checking if the door is open. This has to before the function(s) it's being used in.

function room_Load()
{
  if (isDoorOpen == false)  //check if the door is closed
  {
    RemoveWalkableArea(2);
  }
}

function cVamp_UseInv()
{
  if (player.ActiveInventory == iklaasjaveri) {
    cVamp.Say("Thank you for the blood.");
    cVamp.Say("How can I repay you?");
    player.Say("Let me through the door, maybe?");
    cVamp.Say("Ohh, alright. You deserve it.");
    oDoorOpen.Visible=false;
    oDoorClose.Visible=true;
    player.LoseInventory(iklaasjaveri);
    isDoorOpen = true;//Set the door to "open".
    RestoreWalkableArea(2);
   
  }
}


This will check if the variable "isDoorOpen" is false. If it is, it will remove the walkable area, otherwise it will do nothing (leave the walkable area on).

EDIT - Just noticed that cVamp would be in the GlobalScript. This means you would have to make a global boolean in the Global Variables pane in the editor.
Title: Re: Having problem with walkable areas :(
Post by: beenf on Wed 06/04/2011 14:33:23
I added those both in my room script and global script.
But still same thing. Do I have to make another bool for global script ?
Title: Re: Having problem with walkable areas :(
Post by: Khris on Wed 06/04/2011 14:38:33
Quote from: Creator on Wed 06/04/2011 10:42:08
EDIT - Just noticed that cVamp would be in the GlobalScript. This means you would have to make a global boolean in the Global Variables pane in the editor.
Title: Re: Having problem with walkable areas :(
Post by: beenf on Wed 06/04/2011 14:49:46
Quote from: Khris on Wed 06/04/2011 14:38:33
Quote from: Creator on Wed 06/04/2011 10:42:08
EDIT - Just noticed that cVamp would be in the GlobalScript. This means you would have to make a global boolean in the Global Variables pane in the editor.
I don't know how
Title: Re: Having problem with walkable areas :(
Post by: Matti on Wed 06/04/2011 15:59:36
(http://img5.imageshack.us/img5/5250/glova1.png)

(http://img703.imageshack.us/img703/2540/glova2.png)
Title: Re: Having problem with walkable areas :(
Post by: beenf on Wed 06/04/2011 16:06:49
I knew that part.
But what do I have to write in the boxes and what do I do with it next
Title: Re: Having problem with walkable areas :(
Post by: Matti on Wed 06/04/2011 16:29:42
 ::)

1. You name the variable isDoorOpen

2. You choose the variable type bool

3. You set the variable to false


 ..other than that, Creator showed you what to do. Just ignore the first line where the variable is declared.

Edit: And don't put cVamp_UseInv() in the room script. It should be right there where AGS automatically puts it, in the global script. That's exactly why you need a global variable.
Title: Re: Having problem with walkable areas :(
Post by: beenf on Wed 06/04/2011 18:14:28
Ohh. Finally did it ! Now it's working :P
I deleted

bool isDoorOpen = false;

function cVamp_UseInv()
{
  if (player.ActiveInventory == iklaasjaveri) {
    cVamp.Say("Thank you for the blood.");
    cVamp.Say("How can I repay you?");
    player.Say("Let me through the door, maybe?");
    cVamp.Say("Ohh, alright. You deserve it.");
    oDoorOpen.Visible=true;
    oDoorClose.Visible=false;
    player.LoseInventory(iklaasjaveri);
    isDoorOpen = true;//Set the door to "open".
    RestoreWalkableArea(2);
   
  }
}

from room script and added the bool in global script

Thnx guys. Once again the forum helped out