Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Creator on Sat 03/09/2011 14:52:06

Title: Add more than one inventory item to a character (Self-Solved)
Post by: Creator on Sat 03/09/2011 14:52:06
Is there a way to add more than one item of the same type to a character? I want to add 3 of the same item to my character and, it seems tedious to write this 3 times.


player.AddInventory(iPotion);


Say I was using an inventory item as cash and wanted to add 200 currency to them. Writing it 200 times would seem tedious.

EDIT - Seems I'm a little slow today. Just as I hit post I remembered loops. The cash problem would be solved easily then.


int x = 0;

while(x != 200)
{
 player.AddInventory(iCash);
 x++;
}
Title: Re: Add more than one inventory item to a character (Self-Solved)
Post by: Wyz on Sat 03/09/2011 15:15:39
Yes, but you can also do this:

player.AddInventory(iCash);
player.InventoryQuantity[iCash.ID] = 200;
Title: Re: Add more than one inventory item to a character (Self-Solved)
Post by: Khris on Sat 03/09/2011 17:11:34
The second line alone will do, unless there's on_event stuff happening.
Title: Re: Add more than one inventory item to a character (Self-Solved)
Post by: Creator on Sun 04/09/2011 10:41:57
Quote from: Wyz+ on Sat 03/09/2011 15:15:39

player.AddInventory(iCash);
player.InventoryQuantity[iCash.ID] = 200;


Quote from: Khris on Sat 03/09/2011 17:11:34
The second line alone will do, unless there's on_event stuff happening.

Ah, OK. So there is a built in command to do that, sort of.  :P
Thanks, guys.
Title: Re: Add more than one inventory item to a character (Self-Solved)
Post by: Khris on Sun 04/09/2011 11:21:18
AGS keeps track of inventories using the InventoryQuantity array.
Calling AddInventory or LoseInventory simply increases/decreases the value by one, so you can set it directly instead. This won't call on_event(eEventAdd/LoseInventory, data) though, which might even be preferable here.

I just wanted to counter the impression that you have to add an inventory item before being able to change its amount directly.