need help with using inv items on hotspots

Started by wotmeworry, Thu 15/01/2009 08:18:32

Previous topic - Next topic

wotmeworry

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!

Akatosh

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.

Ghost

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.

Code: ags

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!");
}

Dualnames

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
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Ryan Timothy B

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.

Dualnames

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?
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Lt. Smash

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.

Dualnames

Well, i usually use to put it anyway, but if it's useless there nevermind. Ok?
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Ryan Timothy B

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.

SMF spam blocked by CleanTalk