Get related: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>Bale
comment
imported>Bale
No edit summary
Line 20: Line 20:
<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
if(item_amount($item[black pepper]) == 0)
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")
   foreach thing in get_related($item[black pepper], "zap")
       // It will now check if you have each thing that can zap into black pepper.
       // It will now check if you have each thing that can zap into black pepper.

Revision as of 19:41, 26 February 2010

Function Syntax

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;
      }

Zap for stab bats!

This small program will try to zap something into a tiny plastic stab bat and send it to zarqon. It returns true if successful.

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");
}