Difference between revisions of "CInventory::getItemsCount"
From King Arthur's Gold Wiki
Shadlington (Talk | contribs) (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...") |
Shadlington (Talk | contribs) |
||
Line 1: | Line 1: | ||
<onlyinclude> | <onlyinclude> | ||
− | Returns the number of | + | Returns the number of [[CBlob]] stacks in this inventory as an int. |
</onlyinclude> | </onlyinclude> | ||
− | This very simple method is useful anywhere you need to know how many | + | 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. |
+ | 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. | ||
<syntaxhighlight lang="cpp"> | <syntaxhighlight lang="cpp"> |
Revision as of 20:48, 19 August 2012
Returns the number of CBlob stacks in this inventory as an int.
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.
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