Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: shaungaryevans on Thu 23/10/2008 17:22:56

Title: how to: Inventory item to open a door
Post by: shaungaryevans on Thu 23/10/2008 17:22:56
hi,

I've got a key as a inventory item and i got a locked door. I only want to open the door when the inventory is used and nothing else. Can somebody please tell me how to do it please?
Title: Re: how to: Inventory item to open a door
Post by: RickJ on Thu 23/10/2008 19:45:38
1. Create key inventory item
   - right click inventory in navigation tree
   - select Create new inventory item
   - change name to iKey

2. Create an object in the room and name it oDoor.
   - room edit
   - select object from drop list
   - right click on room background

3. Create a "use inventory on object" event handler function
   - room edit
   - click (lighting bolt icon in properties window
   - click "use inventory on object"
   - clcik "..." button

4.  Edit event handler
   - Add the following code

if (player.HasInventory(iKey)) {
  // Unlock the door animation here
}
Title: Re: how to: Inventory item to open a door
Post by: Khris on Thu 23/10/2008 21:50:11
Most importantly, check player.ActiveInventory (http://www.adventuregamestudio.co.uk/manual/Character.ActiveInventory.htm).
Title: Re: how to: Inventory item to open a door
Post by: RickJ on Thu 23/10/2008 22:39:04
Thanks Khris, I look everywhere for that and could't find the @$#% %$#!@ thing.  :=

By all means use player.ActiveInventory instead of player.HasInventory().
Title: Re: how to: Inventory item to open a door
Post by: shaungaryevans on Fri 24/10/2008 15:47:50
Thanks for that, but it still won't work. The Output window box is saying'  Parse error in expr near 'Cchar' when I put in the following code:

function hdoor1_UseInv() {

if (cChar1.ActiveInventory(iKey))
{Shaun.ChangeRoom(0)} ;

Please tell me where I'm going wrong?
Title: Re: how to: Inventory item to open a door
Post by: Khris on Fri 24/10/2008 16:21:49
if (cChar1.ActiveInventory == iKey)
Title: Re: how to: Inventory item to open a door
Post by: shaungaryevans on Fri 24/10/2008 16:39:29
Thanks alot, it works now.

thanks