Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: JpGames on Tue 15/05/2007 04:45:59

Title: activate walkable areas
Post by: JpGames on Tue 15/05/2007 04:45:59
Well, I'm lost with this  ???

I want create a walkable area, but in one part of it, the player just can access after he complete a puzzle. I mind, a walkable area with a door in the middle. Until the player do not opens the door, he cant access to the other side.

I tried with regions, but the result was no good. Also using 2 diferent walbale areas, but again i cant do it.

Any suggestion? Im sure the solution is very easy, but after almost 2 days i really appreciatte a help here.

JpGames

EDIT Im sorry, i made a mistake and posted this in the wrong thread  ::)
Title: Re: activate walkable areas
Post by: Gilbert on Tue 15/05/2007 05:04:43
Look up RemoveWalkableArea() and RestoreWalkableArea() from the manual.

Basically you can just remove an area in "first time enters room" and then re-enable when the character can walk on it again.
Title: Walkable areas
Post by: JpGames on Tue 15/05/2007 17:53:56
I did that. I used walkable area 1 for the part where the player can walk free, and walkable area 2 for the area acroos the door. When the players open the door, i activate the walkable area 2, but the player can go into that area. I verify the masks, ans both are in contact.

JpGames
Title: Re: Walkable areas
Post by: Khris on Tue 15/05/2007 18:13:03
Quote from: JpGames on Tue 15/05/2007 17:53:56When the players open the door, i activate the walkable area 2, but the player can go into that area.

Well, that's exactly what's supposed to happen, isn't it? ;)
Did you mean that the player can step on area No. 2 before he opened the door?
Or did you mean he can't step on it after the door is open?
Title: Re: activate walkable areas
Post by: Ashen on Tue 15/05/2007 19:13:34
Since it's not the obvious solution it seemed to be, topics merged and unlocked.

JpGames, in future PM a moderator to unlock a thread for you, don't just start a new one.
Title: Re: activate walkable areas
Post by: JpGames on Wed 16/05/2007 07:04:13
Ashen, thanks for your tip.

ok, i have this in the player enters room before fade in:

if (puertaabierta == 0) {
removewalkablearea(2);
}

when the players opens the door, i change the variable (puertaabierta = 1), but the player cant enter in the walkablearea 2  ???

Im sure the variable is good declared and i also imported it. I put a little command to see the value (the player say the value)

if (puertaabierta == 0) {
ccapitan.say ("Its close");
}
if (puertaabierta == 1) {
ccapitan.say ("Its open");
}

And the players says "its open". I cheked, and there are not unfilled spaces between both areas (1 & 2).

I miss something??? Im feeling frustrate with this  :'(

JpGames
Title: Re: activate walkable areas
Post by: Gilbert on Wed 16/05/2007 07:17:08
That's because you probably didn't actually reactivate the area after opening the door. :P

Aside from setting the variable to 1, you need to use RestoreWalkableArea() to reactivate the area.
Title: Re: activate walkable areas
Post by: Andail on Wed 16/05/2007 10:03:05
Yeah, just changing the variable will not change anything in the room until you call the function again.
Title: Re: activate walkable areas (SOLVED)
Post by: JpGames on Thu 17/05/2007 04:10:08
Thanks, that was my mistake to forgot that. Now i working great :)

JpGames
Title: Re: activate walkable areas
Post by: WolfBlacker on Sun 10/06/2007 20:37:43
I don't want to make a new topic because my problem is similar. So:

I've tried with "First time player enters the room" to remove walkable area. To that point evrything is ok, character can't walk on it. But when I want to restore that area, it doesn't work. This is the script for removing:
// script for Room: First time player enters room
{
RemoveWalkableArea (2);
}
}
And this for restoring:
if (player.ActiveInventory == inventory[3]){
  RestoreWalkableArea (2);

  }
Title: Re: activate walkable areas
Post by: Ashen on Sun 10/06/2007 20:57:13
Where have you put the RestoreWalkableArea bit?
Title: Re: activate walkable areas
Post by: WolfBlacker on Sun 10/06/2007 21:25:56
Whole part of the script:

#sectionstart object1_a  // DO NOT EDIT OR REMOVE THIS LINE
function object1_a() {
  // script for Object 1: Use inventory on object
  if (player.ActiveInventory == inventory[3]){
  RestoreWalkableArea (2);

  }
Title: Re: activate walkable areas
Post by: Ashen on Sun 10/06/2007 23:51:21
Are you definitely using the right Item on the right object? Try using the Item's script-o-name (e.g. iKey) instead of inventory[3]. Also, add a couple of Display commands, to check if it's running at all. (Oh, and double check that it's actually Walkable Area 2 you want to be removing/restoring, of course.)
Title: Re: activate walkable areas
Post by: WolfBlacker on Mon 11/06/2007 18:26:07
Well, I think id doesn't work at all, DisplayMessage doesn't work too (and it is just after the RestoreWalkableArea). How to make it working?
Title: Re: activate walkable areas
Post by: Ashen on Mon 11/06/2007 18:37:32
Again, is it definitely the right Item and Object you're using? Try:


  // script for Object 1: Use inventory on object
  Display ("Item %d used on object 1.", player.ActiveInventory.ID);
  if (player.ActiveInventory == inventory[3]){
  RestoreWalkableArea (2);
  }


That should at least tell you what item you're using. If it doesn't display anything, you're either not in the right cursor mode, or clicking the wrong object.
Title: Re: activate walkable areas
Post by: WolfBlacker on Mon 11/06/2007 21:20:09
Well, it shows me an error -.- (I know, I suck at script) I was copying-pasting the code, and it shows me an error about null pointer referenced (I should modify it? Write chracter[EGO] instead of player, and something else?)
Title: Re: activate walkable areas
Post by: Ashen on Mon 11/06/2007 22:24:30
What was the exact error message, and when does it show (when you try to test the game, when you interact with the object ...)?

player is automatically generated so that can't be null, if this is in the 'Use inventory on object' interaction player.ActiveInventory can't be null either ... By elimination it looks like inventory[3] isn't a valid item - again, what if you use the script-o-name instead?
Title: Re: activate walkable areas
Post by: WolfBlacker on Tue 12/06/2007 11:01:35
Exact message:
Error: run_text_script1: error -6 running function 'object1_a':
Error: Null pointer referenced
in Room 1 script (line 6)

Line 6 is the "Display ("Item %d used on object 1.", player.ActiveInventory.ID);". When I'm using the script-o-name, nothing changes.
Title: Re: activate walkable areas
Post by: Gilbert on Tue 12/06/2007 12:08:10
I didn't read all the stuff yet, but when no item is currently selected for a character ActiveInventory will be null.
Try changing the line to:
if (play.ActiveIntory!=null) Display ("Item %d used on object 1.", player.ActiveInventory.ID);
Title: Re: activate walkable areas
Post by: Khris on Tue 12/06/2007 12:12:39
The .ID bit throwing the error was my initial guess, too, and it seems to indeed be the cause, but how come "use inv on object" is called when ActiveInventory==null?

WolfBlacker: Are you using some kind of template? Or the default game?
Title: Re: activate walkable areas
Post by: Ashen on Tue 12/06/2007 12:18:50
Try:

if (player.ActiveInventory != null) Display ("Item %d used on object 1.", player.ActiveInventory.ID);
else Display("No active item");


Just to double check.

However, the original code (this post (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=31255.msg404962#msg404962), a few up) seemed like it was in the 'Use inventory on' interaction - is it possible for that to run with no Active Inventory item? That would certainly explain both the null pointer error and why the code wasn't running in the first place, I just didn't think it could happen...

I wasn't sure about the player.ActiveInventory.ID bit, but I tested before posting and THAT works, so it must be the interaction somehow running with no ActiveItem.
Title: Re: activate walkable areas
Post by: Khris on Tue 12/06/2007 12:39:27
Yeah, I should have been clearer, of course the .ID bit isn't wrong by itself, just calling it while ActiveInventory is null will throw an error.

But, as you've already said, it shouldn't be null in this case.

EDIT: I've done some testing:
-Setting ActiveInventory to an InvItem will automatically change mouse.Mode to eModeUseinv (if the player possesses the item, otherwise the game crashes).
-Setting mouse.Mode to eModeUseinv doesn't have any effect if ActiveInventory is null.
-I was able to replicate the error (i.e. calling "Use inv on object" while ActiveInventory==null), but only by directly calling either ProcessClick(255, 123, eModeUseinv); or oBottle.RunInteraction(eModeUseinv);

Conclusion: Both ProcessClick and RunInteraction shouldn't be called with anything else than mouse.Mode, because in that case mouse.Mode can't be eModeUseinv while ActiveInventory==null.

Further conclusion: Some faulty code is used, probably in on_mouse_click.
Title: Re: activate walkable areas
Post by: WolfBlacker on Tue 12/06/2007 13:39:38
I'm using the default game. And I used the code that Ashen gave - it shows up "No active item".
Title: Re: activate walkable areas
Post by: Khris on Tue 12/06/2007 15:21:38
Are you using any modules or did you copy&paste any other stuff from the forums into your game?
Did you change anything in the cursor pane?

And please post the on_mouse_click from the global script.
Title: Re: activate walkable areas
Post by: WolfBlacker on Tue 12/06/2007 16:19:19
No, I'm not using anything, no modules or script from other forums. And I didn't changed anything.

#sectionstart on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE
function on_mouse_click(MouseButton button) {
  // called when a mouse button is clicked. button is either LEFT or RIGHT
  if (IsGamePaused() == 1) {
    // Game is paused, so do nothing (ie. don't allow mouse click)
  }
  else if (button == eMouseLeft) {
    ProcessClick(mouse.x, mouse.y, mouse.Mode );
  }
  else {   // right-click, so cycle cursor
    mouse.SelectNextMode();
  }
}
#sectionend on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE
Title: Re: activate walkable areas
Post by: Khris on Tue 12/06/2007 16:30:06
This keeps getting weirder.

Just to make sure:
When you are clicking on the object, your cursor is some inventory item graphic, right? It's inv item Nr. 3, correct? No white hand or pointer or something like that?
And directly after the click, you get "No active item"?
Title: Re: activate walkable areas
Post by: WolfBlacker on Tue 12/06/2007 16:55:31
Yes, yes, no, yes. And...
Umm...I don't know what was it, but I've checked the "Don't use inventory graphics as cursors" in the general settings, it still shows up the "No active item" but suddenly...it works O.O'' I've added one walk-behind and I'm testing it again. An error when I've used item on object. Great, what this time? "In Global script (line 60)
Error: ObjectOn: invalid object specified)"
And in global I didn't changed ANYTHING.
Title: Re: activate walkable areas
Post by: Khris on Tue 12/06/2007 19:07:12
By "it works", you mean that now the walkable area is turned back on?
ObjectOn is old code, you shouldn't be using that.
Line 60 contains ProcessClick, so the actual erroneous line is in the room's script.

I'd really like to take a look at the game, could you upload it and PM me the link?

Edit: Alright, I found the problem.
You're removing the inventory item using an action, then using a RunScript-action to enable the walkable area.
1. Removing the active inv item will change player.ActiveInventory to null.
2. You don't need to check for the correct item again because the RunScript-action is already a child action of the Conditional checking which item was used.

We didn't have any idea that you're using all those actions beside the RunScript ones.
Btw. that's the reason why the second error is thrown in the global script; you aren't trying to turn on the object in the room script but using an action. You need to change the number to 3. The object is the fourth one, but object counting starts at 0.

I'd recommend to switch over to scripting. Using the Interaction editor is tedious and error-prone.

And you don't need a dialog just to make the player say something.
If you want to keep using the interaction editor commands, use "Game - Display a message" and in the Message Editor window, select the Character where it says "Display message as:".

Again, I'd really recommend to do it with scripting.
It's as easy as:
  player.Say("Blah.");
Title: Re: activate walkable areas
Post by: WolfBlacker on Tue 12/06/2007 22:08:20
Thanks very much  ::)
Title: Re: activate walkable areas
Post by: Khris on Wed 13/06/2007 09:36:57
You're welcome ::)