Difference between revisions of "CInventory::getItemsCount"

From King Arthur's Gold Wiki
Jump to: navigation, search
(Created page with "<onlyinclude> Returns the number of items in this inventory as an int. </onlyinclude> This very simple method is useful anywhere you need to know how many items are in an invent...")
(No difference)

Revision as of 19:51, 19 August 2012

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