Difference between revisions of "CInventory::getItemsCount"

From King Arthur's Gold Wiki
Jump to: navigation, search
 
Line 3: Line 3:
 
</onlyinclude>
 
</onlyinclude>
  
This very simple method is useful anywhere you need to know how many item stacks are in an inventory or if you need to loop through all items in an inventory.
+
This method is useful anywhere you need to know how many item stacks are in an inventory or if you need to loop through all items in an inventory.
 
It is worth noting that this isn't the total number of items in the inventory, just the total number of separate stacks in it.
 
It is worth noting that this isn't the total number of items in the inventory, just the total number of separate stacks in it.
  

Latest revision as of 21:52, 19 August 2012

Returns the number of CBlob stacks in this inventory as an int.


This method is useful anywhere you need to know how many item stacks are in an inventory or if you need to loop through all items in an inventory. It is worth noting that this isn't the total number of items in the inventory, just the total number of separate stacks in it.

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