Add more than one inventory item to a character (Self-Solved)

Started by Creator, Sat 03/09/2011 14:52:06

Previous topic - Next topic

Creator

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.

Code: ags

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.

Code: ags

int x = 0;

while(x != 200)
{
  player.AddInventory(iCash);
  x++;
}

Wyz

Yes, but you can also do this:
Code: ags

player.AddInventory(iCash);
player.InventoryQuantity[iCash.ID] = 200;
Life is like an adventure without the pixel hunts.

Khris

The second line alone will do, unless there's on_event stuff happening.

Creator

Quote from: Wyz+ on Sat 03/09/2011 15:15:39
Code: ags

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.

Khris

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.

SMF spam blocked by CleanTalk