SOLVED: about UpdateInventory() and inventory items with a quantity of 0

Started by johanvepa, Tue 14/05/2013 21:38:36

Previous topic - Next topic

johanvepa

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?

Phemar

Try using something like:

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


Also, are you sure not trying to access player.InventoryQuantity[] with an an index below zero?

Khris

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.

johanvepa

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.

SMF spam blocked by CleanTalk