Get storage: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>SBThief
Created page with "{{ #vardefine:name|get_storage}}{{ #vardefine:aggregate|yes}}{{ #vardefine:return_type|int [item]}}{{ FunctionPage| name={{#var:name}}| function1={{Function| name={{#var:nam..."
 
imported>SBThief
Document an undocumented function
 
Line 17: Line 17:
code1={{CodeSample|
code1={{CodeSample|
title=Example|
title=Example|
description=This example displays the five most powerful hats in Hangk's that you can equip and use.
description=This example displays the five most powerful hats in Hangk's that you can equip and use.|
code=
code=
<syntaxhighlight>
<syntaxhighlight>

Latest revision as of 01:11, 7 November 2018

Function Syntax

int [item] get_storage()

Returns a map where each key is an item stored in Hangk's, with the integer value its quantity.

Example

This example displays the five most powerful hats in Hangk's that you can equip and use.

int i = 1;
item [int] hats;

batch_open();
// We're using a batch here to minimize server hits.
foreach it in get_storage() {
     if ( !can_equip(it) ) continue;
     if ( !is_unrestricted(it) ) continue;
     if ( to_slot(it) != $slot[hat] ) continue;
     hats[i] = it;
     i += 1;
}
batch_close();

sort hats by -get_power(value);

print("Hats in Hangk's:");
for j from 1 to 5 {
     print(hats[j] + " (" + get_power(hats[j]) + ").");
}