Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: wotmeworry on Thu 15/01/2009 08:18:32

Title: need help with using inv items on hotspots
Post by: wotmeworry on Thu 15/01/2009 08:18:32
I know I just posted a question just like, an hour ago, but I need some help again. :P

ok, basicly, my guy wakes up in a room with a locked door. He finds a key in the room and needs to use it to unlock the door. (yes, I know, cliche :P). How do I make it so the player has to use the key inventory item to unlock the door, but he can't use anything else to unlock the door. please help!
Title: Re: need help with using inv items on hotspots
Post by: Akatosh on Thu 15/01/2009 09:52:46
I believe this problem could be solved by a clever combination of the hotspot's "Use inventory item on hotspot" interaction, an "if" statement, the player.ActiveInventory property and two curly braces.
Title: Re: need help with using inv items on hotspots
Post by: on Thu 15/01/2009 10:22:09
Quote from: Akatosh on Thu 15/01/2009 09:52:46
I believe this problem could be solved by a clever combination of the hotspot's "Use inventory item on hotspot" interaction, an "if" statement, the player.ActiveInventory property and two curly braces.

Intriguing and cunning, and may I add that a friendly "else" will even allow you to take advantage of a player.Say("That doesn't work!"); statement.


if (player.activeinventory == iKey) {
  player.say("I unlocked the door with my key and put it back into my pocket very quickly!");
} else {
  player.Say("Now that won't unlock the door!");
}
Title: Re: need help with using inv items on hotspots
Post by: Dualnames on Fri 16/01/2009 09:07:02
Well, I've run through all topics of the beginners guide to write the Guide. Guess what question was asked every 5 pages at least once? Yours.

So to help you out here:
http://guidetoags.blogspot.com/2009/01/ye-old-key-with-door.html
Title: Re: need help with using inv items on hotspots
Post by: Ryan Timothy B on Fri 16/01/2009 20:28:53
I'm not very familiar with the 'return' command, but why is there a return; command at the end of your If statement Dual?  The If statement is already done why is there a need for Return?  Or am I missing something here.
Title: Re: need help with using inv items on hotspots
Post by: Dualnames on Sat 17/01/2009 21:19:45
The return command stops the script as it is and has some other fabulous uses (can be used inside a function to return a variable value). Try the code without return.. it will be run all. Which we don't want to happen right?
Title: Re: need help with using inv items on hotspots
Post by: Lt. Smash on Sat 17/01/2009 21:34:44
The return isn't necessary. There is no code that will be executed after the return.
The return only has a function when there is code after the else statement which shouldn't run if ( cEgo.ActiveInventory == iKey) is true.
Title: Re: need help with using inv items on hotspots
Post by: Dualnames on Sat 17/01/2009 21:36:35
Well, i usually use to put it anyway, but if it's useless there nevermind. Ok?
Title: Re: need help with using inv items on hotspots
Post by: Ryan Timothy B on Sat 17/01/2009 21:44:09
Quote from: Lt. Smash on Sat 17/01/2009 21:34:44
The return isn't necessary.

That's what I thought.  With no code capable of being run after the interaction, the return is useless.