Preventing a character from leaving a room before acquiring object (solved)

Started by Raze, Sun 20/07/2008 14:02:23

Previous topic - Next topic

Raze

Okay I've had a look and couldn't find a topic on it (although there's so many, sorry if this has been asked before) nor could I find answers in the tutorials (although no doubt they're in there... somewhere buried).

Basically I want my character to refuse to leave a room until he's acquired all objects (in this case, two). The code I'm using at the moment requires the character to use a key to open a door. He'll do this whenever the key is used, but I want him to refuse to leave if he hasn't picked up the other item in the room.

The code at the moment is as follows;

function hHotspot2_UseInv()
{
if(player.ActiveInventory == iKey)
{
  player.Walk(357,  215,  eBlock);
player.ChangeRoom (2);
}
else {
  Display("That's hardly going to work, is it?");
}
}

I need to change this so if you use the key without having the second object (iShaft) in your inventory, he'll say something along the lines of "There's still more to find in here."

I'm using the latest version of AGS, if that helps. Any pointers would be much appreciated. Thanks in advance!

Khris

Code: ags
function hHotspot2_UseInv() {
  if(player.ActiveInventory == iKey) {
    if (player.InventoryQuantity[iShaft.ID] == 1) {
      player.Walk(357,  215,  eBlock);
      player.ChangeRoom (2);
    }
    else Display("There's still more to find in here.");
  }
  else Display("That's hardly going to work, is it?");
}

Raze

That's the code I (thought I) was trying earlier.  ;D I must've messed up a minor detail because whatever I did, it wouldn't work. But copy/pasting yours over worked a treat. Nice one, cheers.

Khris

You might have used () instead of [] with the InventoryQuantity array?

Raze

Nah, it wasn't that, I checked that at the time. I think I had the right code, but in the wrong order (part of it was outside brackets it needed to be inside, and I just wasn't seeing it).

SMF spam blocked by CleanTalk