Difference between revisions of "Get inventory"

From Kolmafia
Jump to navigation Jump to search
imported>Slyz
(Created page with '{{ #vardefine:name|get_inventory}}{{ #vardefine:aggregate|yes}}{{ #vardefine:return_type|int [item]}}{{ FunctionPage| name={{#var:name}}| function_category=Item Management| fun…')
 
imported>Bale
m
 
(2 intermediate revisions by 2 users not shown)
Line 6: Line 6:
 
FunctionPage|
 
FunctionPage|
 
name={{#var:name}}|
 
name={{#var:name}}|
function_category=Item Management|
 
  
 
function1={{Function|
 
function1={{Function|
Line 14: Line 13:
 
return_also={{#var:return_also}}|
 
return_also={{#var:return_also}}|
 
}}|
 
}}|
function_description=Returns a map whose keys are the items in your inventory, associated with their quantity.|
+
function_description=Returns a map where each key is an item in your inventory, with the integer value its quantity.|
  
 
code1={{CodeSample|
 
code1={{CodeSample|
Line 21: Line 20:
 
code=
 
code=
 
<syntaxhighlight>
 
<syntaxhighlight>
 +
batch_open();
 
int[item] inventory = get_inventory() ;
 
int[item] inventory = get_inventory() ;
 
foreach it in inventory
 
foreach it in inventory
 
   if ( inventory[it] > 5 )  
 
   if ( inventory[it] > 5 )  
 
       put_closet( 1, it ) ;
 
       put_closet( 1, it ) ;
 +
batch_close();
 +
// We're using a batch here to minimize server hits.
 
</syntaxhighlight>}}|
 
</syntaxhighlight>}}|
 +
}}
  
}}
+
[[Category:Item Management]]

Latest revision as of 21:48, 21 May 2010

Function Syntax

int [item] get_inventory()

Returns a map where each key is an item in your inventory, with the integer value its quantity.

Simple Example

This example puts one of each item of your inventory in your closet if you have more than 5:

batch_open();
int[item] inventory = get_inventory() ;
foreach it in inventory
   if ( inventory[it] > 5 ) 
      put_closet( 1, it ) ;
batch_close();
// We're using a batch here to minimize server hits.