Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: SilverSpook on Tue 19/01/2016 09:02:48

Title: Delete All Items In Inventory
Post by: SilverSpook on Tue 19/01/2016 09:02:48
Is it possible to delete all of the items in a players inventory, no matter what the item is? 

I am thinking of just using the "LoseInventory" function for each item, but the thing is I can't be certain what all items will be in the inventory at a certain time.

What is the best way to do this?  Thanks
Title: Re: Delete All Items In Inventory
Post by: AnasAbdin on Tue 19/01/2016 09:06:21
Code (ags) Select
int j = 0;
    while (j < (Game.InventoryItemCount ))
    {
      cEgo.LoseInventory(inventory[ j ]);
      j++;
    }
Title: Re: Delete All Items In Inventory
Post by: Khris on Tue 19/01/2016 13:52:59
InventoryItem numbering starts at 1, not 0.
Plus, if the player is able to pick up more than one of one or more items, you need to remove every single one.
You can add an inner loop, or do this:
  int j = 1;
  while (j <= Game.InventoryItemCount)
  {
    player.InventoryQuantity[j] = 0;
    j++;
  }
  UpdateInventory();  // changing .InventoryQuantity requires manually updating the inventory GUI
Title: Re: Delete All Items In Inventory
Post by: selmiak on Tue 19/01/2016 18:34:35
Quote from: Khris on Tue 19/01/2016 13:52:59
InventoryItem numbering starts at 1, not 0.
Wouldn't it be easy to just delete the complete inventory with
Code (ags) Select
cEgo.LoseInventory(0);
Should I add this to the feature requests or are there possible complications?
Title: Re: Delete All Items In Inventory
Post by: Crimson Wizard on Tue 19/01/2016 19:16:36
Quote from: selmiak on Tue 19/01/2016 18:34:35
Wouldn't it be easy to just delete the complete inventory with
Code (ags) Select
cEgo.LoseInventory(0);
Should I add this to the feature requests or are there possible complications?
LoseInventory takes pointer, not index number.
As for deleting all there should better be a separate function. Using nullpointer to delete everything is a bit counter-intuitive.
Title: Re: Delete All Items In Inventory
Post by: SilverSpook on Tue 19/01/2016 22:43:08
Ok thanks!