Get shop: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>Lilac
Adding page, as per function added in r11483.
 
imported>Gausie
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{#vardefine:name|get_shop}}
{{#vardefine:name|get_shop}}{{
{{#vardefine:aggregate|yes}}
#vardefine:aggregate|yes}}{{
{{#vardefine:return_type|int [item]}}
#vardefine:return_type|int [item]}}{{


{{
FunctionPage|
FunctionPage|
name={{#var:name}}|
name={{#var:name}}|
Line 14: Line 13:
}}|
}}|
function_description=Returns a map where each key is an item in your Mall store, with the integer value how many you are currently selling.|
function_description=Returns a map where each key is an item in your Mall store, with the integer value how many you are currently selling.|
see_also={{SeeAlso|shop_amount}}
code1={{CodeSample|
title=Code Samples|
description=The following example creates a function called "in_shop" which tells you how many of a given item is currently in your shop.|
code=
<syntaxhighlight>
int[item] shop_items;
shop_items = get_shop();
 
void in_shop(string check) {
  item thing = to_item(check);
  if (thing == $item[none]) {
      print(check+" is not a valid item.", "red");
      return;
  }
  if (shop_items contains thing)
      print("Your shop currently has "+shop_items[thing]+" "+thing+".", "blue");
  else print("Your shop currently has 0 of "+thing, "blue");
}
 
//Check how many Mae Wests
in_shop("mae west");
//Check all items with greater than 4 fullness
foreach it in $items[]
  if (it.fullness > 4)
      in_shop(to_string(it));
 
</syntaxhighlight>|
 
}}|
see_also={{SeeAlso|shop_amount|shop_limit}}|
}}
}}


[[Category:Item Management]]
[[Category:Item Management]]

Latest revision as of 11:03, 24 August 2020

Function Syntax

int [item] get_shop()

Returns a map where each key is an item in your Mall store, with the integer value how many you are currently selling.

Code Samples

The following example creates a function called "in_shop" which tells you how many of a given item is currently in your shop.

int[item] shop_items;
shop_items = get_shop();

void in_shop(string check) {
   item thing = to_item(check);
   if (thing == $item[none]) {
      print(check+" is not a valid item.", "red");
      return;
   }
   if (shop_items contains thing)
      print("Your shop currently has "+shop_items[thing]+" "+thing+".", "blue");
   else print("Your shop currently has 0 of "+thing, "blue");
}

//Check how many Mae Wests
in_shop("mae west");
//Check all items with greater than 4 fullness
foreach it in $items[]
   if (it.fullness > 4)
      in_shop(to_string(it));

See Also

shop_amount() | shop_limit()