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++;
}
Yes, but you can also do this:
player.AddInventory(iCash);
player.InventoryQuantity[iCash.ID] = 200;
The second line alone will do, unless there's on_event stuff happening.
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.
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.