SOLVED Having problem with walkable areas :(

Started by beenf, Tue 05/04/2011 16:51:56

Previous topic - Next topic

beenf

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:
Code: ags

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

TomatoesInTheHead

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?

beenf

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?

TomatoesInTheHead

Since you already use the condition
Code: ags
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.


TomatoesInTheHead

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.

Creator

#6
To expand a little on what TomatosInTheHead said, you could use a boolean (we'll call it "isDoorOpen").

Code: ags

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.

beenf

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 ?

Khris

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.

beenf

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


beenf

I knew that part.
But what do I have to write in the boxes and what do I do with it next

Matti

#12
 ::)

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.

beenf

Ohh. Finally did it ! Now it's working :P
I deleted
Code: ags

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

SMF spam blocked by CleanTalk