Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Gepard on Sun 08/11/2009 14:24:26

Title: How to lose every inventory item?
Post by: Gepard on Sun 08/11/2009 14:24:26
I want my character after performing a certain action to lose every inventory item that he posses. Is it possible to do?

Thanks.
Title: Re: How to lose every inventory item?
Post by: Khris on Sun 08/11/2009 14:36:01
 int i;
 while (i < Game.InventoryItemCount) {
   player.inventory[i] = 0;
   i++;
 }


That should do it.

Edit: Yup, ignore this and look below for the correct way. I hope it served at least as a pointer in the right direction.
Title: Re: How to lose every inventory item?
Post by: Ryan Timothy B on Mon 09/11/2009 21:21:26
.inventory is not a public member of player/character.
Title: Re: How to lose every inventory item?
Post by: monkey0506 on Mon 09/11/2009 21:29:11
The property is .InventoryQuantity and IIRC inventory items start from 1 not 0, so:

  int i = 1;
  while (i <= Game.InventoryItemCount) {
    player.InventoryQuantity[i] = 0;
    i++;
  }


You may also want to call UpdateInventory() at the end of the loop.

Taking it one step further you could implement an extender method such as this:

function LoseAllInventory(this Character*) {
  int i = 1;
  while (i <= Game.InventoryItemCount) {
    player.InventoryQuantity[i] = 0;
    i++;
  }
  UpdateInventory();
}


And then:

player.LoseAllInventory();

(See Also: import keyword in the manual :P)
Title: Re: How to lose every inventory item?
Post by: Ryan Timothy B on Mon 09/11/2009 21:40:14
Thanks Monkey. 
Oddly enough I was searching the forums for the answer to this for myself, for my own game, and was directed to this newly created post.  Now that's luck. :P