CInventory::getItemsCount

From King Arthur's Gold Wiki
Revision as of 18:51, 19 August 2012 by Shadlington (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Returns the number of items in this inventory as an int.


This very simple method is useful anywhere you need to know how many items are in an inventory or if you need to loop through all items in an inventory.

int getItemsCount()

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