Get related: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>Heeheehee
m Removing specified language so it'll use the default.
imported>Heeheehee
m Missed one, Z.
 
(14 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{FunctionPage |
{{
page_name=get_related|
#vardefine:name|get_related}}{{
function_category=Miscellaneous|
#vardefine:aggregate|yes}}{{
function1_return_type=int [item]|
#vardefine:return_type|int [item]}}{{
function1_parameter1={{Param|item|doodad}} |
 
function1_parameter2={{Param|string|type}} |
FunctionPage|
function1_parameter1_desc=doodad is the item to check.|
name={{#var:name}}|
function1_parameter2_desc=type is "zap" or "fold".
 
* "zap" returns the zap group that the item is part of.  The integer values
function1={{Function|
in the map are meaningless in this case, and the item itself isn't included.
name={{#var:name}}|
* "fold" returns the fold group that the item is part of.  The integer is the
aggregate={{#var:aggregate}}|
position in the fold sequence (1..N), and the item itself IS included, so you
return_type={{#var:return_type}}|
can determine its position.|
return_also={{#var:return_also}}|
function_description=Retrieves some variable-length internal data that
parameter1={{Param|item|doodad}}|
isn't readily readable via file_to_map().|
parameter2={{Param|string|type}}|
code1={{CodeSample |
p1desc={{Pspan|doodad}} is the item to check.|
p2desc={{Pspan|type}} is one of "zap", "fold", or "pulverize".
* "zap" returns the zap group that the item is part of.  The integer values in the map are meaningless in this case, and the item itself isn't included.
* "fold" returns the fold group that the item is part of.  The integer is the position in the fold sequence (1..N), and the item itself IS included, so you can determine its position.
* "pulverize" returns the average products of pulverizing one million of the given item. The scaling is needed to preserve accuracy for the elemental gems, which can be produced at rates as low as 1/1200.|}}|
function_description=Retrieves some variable-length internal data that isn't readily readable via [[file_to_map|file_to_map()]].|
 
code1={{CodeSample|
title=Simple Example|
title=Simple Example|
description=If you need black pepper, this will try to zap something into it.|
description=If you need black pepper, this will try to zap something into it.|
Line 28: Line 35:
         break;
         break;
       }
       }
 
// Note: this simple example doesn't check your wand's state & is therefore not recommended for actual use.
</syntaxhighlight>}} |
</syntaxhighlight>}}
code2={{CodeSample |
{{CodeSample|
title=Zap for stab bats! |
title=Zap for stab bats!|
description=This small program will try to zap something into a tiny plastic stab bat and send it to zarqon.|
description=This small program will try to zap something into a tiny plastic stab bat and send it to zarqon.|
code=
code=
Line 52: Line 59:
       print("Couldn't get a new tiny plastic stab bat today.", "olive");
       print("Couldn't get a new tiny plastic stab bat today.", "olive");
}
}
</syntaxhighlight>}} |
</syntaxhighlight>}}
 
{{CodeSample|
title=Pulverization|
description=This function will detect if a pulverization has any affect on an item.|
code=
<syntaxhighlight>
boolean is_pulverizable(item it) {
  int [item] pulvy = get_related(it, "pulverize");
  if(pulvy contains $item[useless powder])
      return false; // Let's not count useless powder...
  if(count(pulvy) > 0)
      return true;  // Yay! Something useful!
  // Powders and nuggets can be pulverized also!
  if(it.to_int() >= 1438 && it.to_int() <=1449)
      return true;
  switch(it) {
  case $item[sewer nugget]:
  case $item[floaty pebbles]:
  case $item[floaty gravel]:
      // These things can be turned into wads!
      return true;
  }
  return false;
}
 
</syntaxhighlight>}}|
 
see_also={{SeeAlso|file_to_map}}|
special=Specifying anything other than "zap", "fold", or "pulverize" for the second parameter will return an empty map.|
}}
}}
[[Category:Item Management]]

Latest revision as of 17:04, 7 April 2011

Function Syntax

int [item] get_related(item doodad ,string type )

  • doodad is the item to check.
  • type is one of "zap", "fold", or "pulverize".
    • "zap" returns the zap group that the item is part of. The integer values in the map are meaningless in this case, and the item itself isn't included.
    • "fold" returns the fold group that the item is part of. The integer is the position in the fold sequence (1..N), and the item itself IS included, so you can determine its position.
    • "pulverize" returns the average products of pulverizing one million of the given item. The scaling is needed to preserve accuracy for the elemental gems, which can be produced at rates as low as 1/1200.

Retrieves some variable-length internal data that isn't readily readable via file_to_map().

Simple Example

If you need black pepper, this will try to zap something into it.

if(item_amount($item[black pepper]) == 0)
   // Here's the function! This will loop over every item that can be zapped into black pepper.
   foreach thing in get_related($item[black pepper], "zap")
      // It will now check if you have each thing that can zap into black pepper.
      if(item_amount(thing)> 0) {
         // zap the item and end the foreach loop.
         cli_execute("zap "+thing);
         break;
      }
// Note: this simple example doesn't check your wand's state & is therefore not recommended for actual use.

Zap for stab bats!

This small program will try to zap something into a tiny plastic stab bat and send it to zarqon.

boolean stab_zap() {
   int starting_stabbies = item_amount($item[tiny plastic stab bat]);
   foreach doohicky in get_related($item[tiny plastic stab bat], "zap")
      if(item_amount(doohicky) > 0) {
         cli_execute("zap "+doohicky);
         return item_amount($item[tiny plastic stab bat]) > starting_stabbies;
      }
   return false;
}

void main() {
   if(stab_zap()) {
      cli_execute("send 1 tiny plastic stab bat to zarqon | Something for your awesome bat collection!");
      print("Sent a tiny plastic stab bat to zarqon.", "blue");
   } else
      print("Couldn't get a new tiny plastic stab bat today.", "olive");
}


Pulverization

This function will detect if a pulverization has any affect on an item.

boolean is_pulverizable(item it) {
   int [item] pulvy = get_related(it, "pulverize");
   if(pulvy contains $item[useless powder])
      return false; // Let's not count useless powder...
   if(count(pulvy) > 0)
      return true;  // Yay! Something useful!
   // Powders and nuggets can be pulverized also!
   if(it.to_int() >= 1438 && it.to_int() <=1449)
      return true;
   switch(it) {
   case $item[sewer nugget]:
   case $item[floaty pebbles]: 
   case $item[floaty gravel]:
      // These things can be turned into wads!
      return true;
   }
   return false;
}

See Also

file_to_map()

Special

Specifying anything other than "zap", "fold", or "pulverize" for the second parameter will return an empty map.