Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Stupot on Fri 13/09/2013 20:07:36

Title: Item not disappearing from inventory
Post by: Stupot on Fri 13/09/2013 20:07:36
Hi all.

Am I missing something really obvious?
When I give a certain item to another character I want the item to disappear from my inventory.
Code (ags) Select

function cBarman_UseInv()
{
  if (cEgo.ActiveInventory == iNewPretzels)
  {
    cEgo.Say("Dialogue");   
    cBarman.Say("Dialogue");

    cEgo.LoseInventory(iNewPretzels);
  } 
}

Why then, Do I still have the iNewPretzels in my inventory after this exchange (and still the ActiveInventory)?

Is there any known reason why this could be the case?
Title: Re: Item not disappearing from inventory
Post by: Andail on Fri 13/09/2013 21:36:22
The only thing I can think of is that you have multiple copies of the item. You have probably given your character the item twice in the code before.
Title: Re: Item not disappearing from inventory
Post by: Stupot on Fri 13/09/2013 21:45:21
Yep. That's exactly what's happened.
I can't even work out how he ends up with two tokens of the item, but running  cEgo.LoseInventory(iNewPretzels);  twice eliminates the problem.
Thanks man :)
Title: Re: Item not disappearing from inventory
Post by: Andail on Fri 13/09/2013 21:57:38
You should probably find the source, though :) You haven't by any chance ticked the character-starts-with-this-item for testing purposes? In case you can't find it in the code.
Title: Re: Item not disappearing from inventory
Post by: Stupot on Fri 13/09/2013 22:10:19
I still can't exactly get my head around it, but in the function where you actually get the item in the first place I have changed it from  if, if, else  to  if, else if, else,  (which is what I probably meant to do in the first place) and that seems to have done the trick :)
Title: Re: Item not disappearing from inventory
Post by: Andail on Fri 13/09/2013 22:13:57
Well, I guess you had two conditions that both were true and both awarded the item. With the additional "else" you have made sure only one is run. Glad to hear it's solved anyway :)