Item not disappearing from inventory

Started by Stupot, Fri 13/09/2013 20:07:36

Previous topic - Next topic

Stupot

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

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?
MAGGIES 2024
Voting is over  |  Play the games

Andail

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.

Stupot

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 :)
MAGGIES 2024
Voting is over  |  Play the games

Andail

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.

Stupot

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 :)
MAGGIES 2024
Voting is over  |  Play the games

Andail

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 :)

SMF spam blocked by CleanTalk