Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: johanvepa on Tue 14/05/2013 21:38:36

Title: SOLVED: about UpdateInventory() and inventory items with a quantity of 0
Post by: johanvepa on Tue 14/05/2013 21:38:36
How come inventory items still appear as a cursor and in the active inventory item window, even if the quantity of said item is 0 and I've used UpdateInventory()?

Like, cEgo picks up a bunch of carrots. so inventoryquantity is 5. He then eats 4. no problem, theres one left, its still visible in inventory and in acitive inventory. then he eats one more, and the item disappears from the inventory. but it's still there as a cursor item! and if I try to "eat" the zero quantity carrot, then the game crashes. I can work around it by using a display related to there being 0 carrots, but it's unwieldy and buggy.

what can I do?
Title: Re: A question about UpdateInventory() and inventory items with a quantity of 0
Post by: Phemar on Tue 14/05/2013 23:38:01
Try using something like:

Code (ags) Select
if (!player.HasInventory(player.ActiveInventory))
  player.ActiveInventory = null;


Also, are you sure not trying to access player.InventoryQuantity[] with an an index below zero?
Title: Re: A question about UpdateInventory() and inventory items with a quantity of 0
Post by: Khris on Wed 15/05/2013 11:07:49
Are you using player.LoseInventory() to remove the carrots?
If you do, and removing the last one doesn't set player.ActiveInventory to null, you simply have to do it yourself.
Title: Re: A question about UpdateInventory() and inventory items with a quantity of 0
Post by: johanvepa on Wed 15/05/2013 21:14:41
Quote from: Khris on Wed 15/05/2013 11:07:49
Are you using player.LoseInventory() to remove the carrots?
If you do, and removing the last one doesn't set player.ActiveInventory to null, you simply have to do it yourself.

That's the baby. I'd blinded myself to using only InventoryQuantity(). Thanks.