CInventory::getItem

From King Arthur's Gold Wiki
Jump to: navigation, search

Returns a reference to the CBlob at the given index in this inventory's item list.


This method is really only useful if you are looping through all items in an inventory or if you otherwise know the specific index of the item you want - most likely because the inventory you're dealing with only accepts a single item at a time, like a catapult.

CBlob@ getItem(int index)

Example from Entities/Vehicles/Scripts/CatapultLogic.as:

if (this.getInventory().getItemsCount() > 0)
{
  fireLabel = "FIRE ";
  fireLabel += this.getInventory().getItem(0).getInventoryName();  fireIcon = 10;
}

Example from Entities/Common/Scripts/Merges.as:

void onAddToInventory( CBlob@ this, CBlob@ inventoryBlob )
{
  // merge item in inventory
  for (int i = 0; i < inventoryBlob.getInventory().getItemsCount(); i++)
  {
    CBlob @blob = inventoryBlob.getInventory().getItem(i);    if (blob !is this && blob.getName() == this.getName())
    {
      blob.SetQuantity( blob.getQuantity() + this.getQuantity() );				
      if (this.getSprite() !is null)
        this.getSprite().getVars().gibbed = true;
      this.Die();	
      break;		
    }
  }
}

Object method of: CInventory