Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: MRollins on Fri 01/02/2008 23:54:07

Title: How can I specify which Inv object to use for the "_UseInv" function?
Post by: MRollins on Fri 01/02/2008 23:54:07
I am trying to figure out how to limit the below function to only work when I use a specific inv item on a character. Currently, this function is starting when I use ANY inventory item on the character. I've looked all over the manual so any help would be appreciated.

function cTraderwick_UseInv()
{
cEgo.Walk(77, 125, eBlock);
dialog[1].Start();
player.LoseInventory(iEgg);
player.AddInventory(iHabGrant);
}
Title: Re: How can I specify which Inv object to use for the "_UseInv" function?
Post by: monkey0506 on Sat 02/02/2008 03:16:51
You could use the player's active inventory item for this:

function cTraderwick_UseInv()
{
  if (player.ActiveInventory == iEgg) // player used iEgg on cTraderwick
  {
    cEgo.Walk(77, 125, eBlock);
    // is cEgo the player? if so, it is recommended to replace "cEgo" with "player" in case you change the player character later ;)
    dialog[1].Start();
    player.LoseInventory(iEgg);
    player.AddInventory(iHabGrant);
  }
}


As I denoted by the comment, if cEgo is your player character, you may want to use the player keyword instead of using cEgo directly. That way in case you change your player character later you won't have any strange problems. ;)

BTW, this is the exact same issue as the one posted here (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=33633.0) today. Just for future reference, the forum has a search function (http://www.adventuregamestudio.co.uk/yabb/index.php?action=search) so you can check for related issues. This serves two purposes: 1) it can help you find your answer yourself! and 2) it will save you the stress of dealing with angry moderators telling you to read the rules! ;D
Title: Re: How can I specify which Inv object to use for the "_UseInv" function?
Post by: MRollins on Sat 02/02/2008 03:48:49
Wow, I even tried to search the forums for it and I still didn't see it.  >:(

Thanks for the help!