<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.kolmafia.us/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=PsyMar</id>
	<title>Kolmafia - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.kolmafia.us/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=PsyMar"/>
	<link rel="alternate" type="text/html" href="https://wiki.kolmafia.us/index.php?title=Special:Contributions/PsyMar"/>
	<updated>2026-04-25T00:22:17Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://wiki.kolmafia.us/index.php?title=Zlib&amp;diff=7295</id>
		<title>Zlib</title>
		<link rel="alternate" type="text/html" href="https://wiki.kolmafia.us/index.php?title=Zlib&amp;diff=7295"/>
		<updated>2013-12-04T14:28:24Z</updated>

		<summary type="html">&lt;p&gt;PsyMar: /* Adventuring Functions */ the third parameter of obtain is &amp;quot;location place&amp;quot;, this is named place and is of type location, not vice-versa (as the comments below the function previously indicated)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{TOCright}}{{DISPLAYTITLE:ZLib (zlib.ash)}}&lt;br /&gt;
{{Attention|&lt;br /&gt;
This page details the use of functions in a script library. The information here is only useful to those who have followed the included steps to make use of these functions; they are not built-in to KoLmafia.&lt;br /&gt;
}}&lt;br /&gt;
== About ZLib ==&lt;br /&gt;
ZLib is a function library intended to make life easier for both script authors and script users.  A more detailed introduction, as well as instructions on installing it and other details, can be found in the [http://kolmafia.us/showthread.php?2072 ZLib thread].&lt;br /&gt;
&lt;br /&gt;
== String Functions ==&lt;br /&gt;
&lt;br /&gt;
{{HideLink|excise}}{{Function|&lt;br /&gt;
name=excise|&lt;br /&gt;
return_type=string|&lt;br /&gt;
parameter1={{Param|string|source}}|&lt;br /&gt;
parameter2={{Param|string|start}}|&lt;br /&gt;
parameter3={{Param|string|end}}|&lt;br /&gt;
p1desc=The original {{pspan|source}} string|&lt;br /&gt;
p2desc={{pspan|start}} after this string|&lt;br /&gt;
p3desc={{pspan|end}} before this string|&lt;br /&gt;
}}&lt;br /&gt;
This function returns a portion of the {{pspan|source}} string, from after the first occurrence of {{pspan|start}} to just before the first occurrence of {{pspan|end}}. If either {{pspan|start}} or {{pspan|end}} are missing, it will return an empty string. You can also supply either {{pspan|start}} or {{pspan|end}} as blank strings to specify the actual start or end of the {{pspan|source}} string.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|equals}}{{Function|&lt;br /&gt;
name=equals|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|string|s1}}|&lt;br /&gt;
parameter2={{Param|string|s2}}|&lt;br /&gt;
p1desc={{pspan|s1}} is a string.|&lt;br /&gt;
p2desc={{pspan|s2}} is the string to compare with {{pspan|s1}}.|&lt;br /&gt;
}}&lt;br /&gt;
Since string comparisons in ASH using == and != are case-insensitive, this function allows you to strictly compare two strings, including case sensitivity.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|vprint}}{{Function|&lt;br /&gt;
name=vprint|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|string|message}}|&lt;br /&gt;
parameter2={{Param|int|level}}|&lt;br /&gt;
}}&lt;br /&gt;
{{Function|&lt;br /&gt;
name=vprint|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|string|message}}|&lt;br /&gt;
parameter2={{Param|string|color}}|&lt;br /&gt;
parameter3={{Param|int|level}}|&lt;br /&gt;
p1desc={{pspan|message}} and {{pspan|color}} are used as in the function {{f|print}}|&lt;br /&gt;
p2desc={{pspan|level}} controls the return value and specifies the verbosity level of the message|&lt;br /&gt;
}}&lt;br /&gt;
This function is an enhanced version of the ASH function {{f|print}}.  The {{pspan|message}} and optional {{pspan|color}} parameters are exactly like in print(), but the {{pspan|level}} parameter gives you a lot of additional control.  Specifically, it allows you to control the return value, specify the verbosity level of the output, and maybe even abort the script.&lt;br /&gt;
&lt;br /&gt;
First, the return value.  If level is positive, it returns true.  If negative, it returns false.  If level is 0, vprint() will abort with the specified message. You can see now that vprint effectively replaces both {{f|abort}} and print.  I recommend it as your go-to function anytime you need to show anything in the CLI, for any reason.&lt;br /&gt;
&lt;br /&gt;
Having a boolean return value (as opposed to ASH&#039;s print returning void) allows you to include helpful information in your script easily, without needing to significantly edit your code.  For example:&lt;br /&gt;
{{CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
// add debugging info to an if check:&lt;br /&gt;
if (somevar == 2 &amp;amp;&amp;amp; vprint(&amp;quot;somevar equals 2&amp;quot;,10)) dosomething();&lt;br /&gt;
// add additional info to a return true/false:&lt;br /&gt;
if (everythingsgreat) return vprint(&amp;quot;Everything&#039;s great!&amp;quot;,7);&lt;br /&gt;
   else return vprint(&amp;quot;Everything is not great.&amp;quot;,-7);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Secondly, level represents the verbosity of the message.  ZLib includes a script setting called &amp;quot;verbosity&amp;quot;.  Users can adjust this value to specify how verbose they want scripts to be.  If they set it to 1, they want the script to print almost nothing -- only the most important messages.  If they set it to 10, they want it to print a lot of details.  The level of each vprint command thus determines whether or not the message will actually be printed.  If the absolute value of level is more than verbosity, the message will not be printed.  For example, a user with the default verbosity of 3 would not see any of the example messages given above.  This allows users to control the chattiness of scripts, and allows authors to include helpful debugging print statements which can be shown by setting verbosity high.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recommendations for Verbosity Levels in vprint()&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
0: abort error&lt;br /&gt;
&lt;br /&gt;
+/- 1: absolutely essential (and non-cluttering) information -- use very sparingly, since a verbosity of 1 is basically &amp;quot;silent mode&amp;quot;&lt;br /&gt;
&lt;br /&gt;
+/- 2: important and useful info -- this should generally be your base level for your most important messages&lt;br /&gt;
&lt;br /&gt;
+/- 4: interesting but non-essential information&lt;br /&gt;
&lt;br /&gt;
+/- 6: info which an overly curious person might like to see on their CLI&lt;br /&gt;
&lt;br /&gt;
+/- 10: details which are only helpful for debugging, such as &amp;quot;begin/end functionname()&amp;quot; or &amp;quot;current value of variable: value&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This will allow users who want extra levels of detail printed to see that detail without cluttering the CLI for users who don&#039;t prefer to see all the details. In addition, it allows users to specify a verbosity of 0 to see ONLY mafia output (no script output at all), which could prove handy.&lt;br /&gt;
&lt;br /&gt;
The color parameter is optional.  If you omit it, the default color is black for positive values of level, and red for negative values. Usually, you won&#039;t be calling vprint() with the color parameter, unless you want to specify a different color or override the default colors.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|vprint_html}}{{Function|&lt;br /&gt;
name=vprint_html|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|string|message}}|&lt;br /&gt;
parameter2={{Param|int|level}}|&lt;br /&gt;
p1desc={{pspan|message}} is used as in the function {{f|print_html}}|&lt;br /&gt;
p2desc={{pspan|level}} is a verbosity reference|&lt;br /&gt;
}}&lt;br /&gt;
Same as vprint() above, but wraps {{f|print_html}}.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|normalized}}{{Function|&lt;br /&gt;
name=normalized|&lt;br /&gt;
return_type=string|&lt;br /&gt;
parameter1={{Param|string|mixvar}}|&lt;br /&gt;
parameter2={{Param|string|type}}|&lt;br /&gt;
p1desc={{pspan|mixvar}} is the string to normalize|&lt;br /&gt;
p2desc={{pspan|type}} is the datatype to normalize to, which can be any primitive type or any typed constant.  You can also specify &amp;quot;list of &amp;lt;type&amp;gt;&amp;quot;, for a comma-delimited list of the given type.|&lt;br /&gt;
}}&lt;br /&gt;
Returns {{pspan|mixvar}}, normalized to the specified KoLmafia {{pspan|type}}. For example, normalized(&amp;quot;badger&amp;quot;, &amp;quot;familiar&amp;quot;) would return &amp;quot;Astral Badger&amp;quot;.  It can also normalize comma-delimited lists of any of these types if you specify &amp;quot;list of &amp;lt;type&amp;gt;&amp;quot; for {{pspan|type}}.  For example, normalized(&amp;quot;bloop, dair go, possess&amp;quot;, &amp;quot;list of monster&amp;quot;) would return &amp;quot;Blooper, Dairy Goat, Possessed Silverware Drawer&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|join}}{{Function|&lt;br /&gt;
name=join|&lt;br /&gt;
return_type=string|&lt;br /&gt;
parameter1={{Param|string [int]|pieces|ag=t}}|&lt;br /&gt;
parameter2={{Param|string|glue}}|&lt;br /&gt;
p1desc={{pspan|pieces}} is a map of strings which you want to join into a single string.|&lt;br /&gt;
p2desc={{pspan|glue}} is the string to put between the pieces.|&lt;br /&gt;
}}&lt;br /&gt;
This function is the opposite of the ASH function {{f|split_string}}.  It joins {{pspan|pieces}} together, inserting {{pspan|glue}} between each piece, and returns the assembly as a single string.  Useful for working with comma-delimited lists (or anything-delimited lists, actually).&lt;br /&gt;
&lt;br /&gt;
{{HideLink|list_contains}}{{Function|&lt;br /&gt;
name=list_contains|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|string|list}}|&lt;br /&gt;
parameter2={{Param|string|needle}}|&lt;br /&gt;
}}&lt;br /&gt;
{{Function|&lt;br /&gt;
name=list_contains|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|string|list}}|&lt;br /&gt;
parameter2={{Param|string|needle}}|&lt;br /&gt;
parameter3={{Param|string|glue}}|&lt;br /&gt;
p1desc={{pspan|list}} is a glue-delimited string list such as returned by join().|&lt;br /&gt;
p2desc={{pspan|needle}} is the entry to check for.|&lt;br /&gt;
p3desc={{pspan|glue}} is optional (defaults to &amp;quot;, &amp;quot;) and represents the delimiter for the list.|&lt;br /&gt;
}}&lt;br /&gt;
Returns true if {{pspan|list}} contains {{pspan|needle}}.  Avoids false positives which could result from using contains_text().&lt;br /&gt;
&lt;br /&gt;
{{HideLink|list_add}}{{Function|&lt;br /&gt;
name=list_add|&lt;br /&gt;
return_type=string|&lt;br /&gt;
parameter1={{Param|string|list}}|&lt;br /&gt;
parameter2={{Param|string|add}}|&lt;br /&gt;
}}&lt;br /&gt;
{{Function|&lt;br /&gt;
name=list_add|&lt;br /&gt;
return_type=string|&lt;br /&gt;
parameter1={{Param|string|list}}|&lt;br /&gt;
parameter2={{Param|string|add}}|&lt;br /&gt;
parameter3={{Param|string|glue}}|&lt;br /&gt;
p1desc={{pspan|list}} is a glue-delimited string list such as returned by join() above.|&lt;br /&gt;
p2desc={{pspan|add}} is the entry to add to the list.|&lt;br /&gt;
p3desc={{pspan|glue}} is optional (defaults to &amp;quot;, &amp;quot;) and represents the delimiter for the list.|&lt;br /&gt;
}}&lt;br /&gt;
Adds unique entry {{pspan|add}} to a {{pspan|glue}}-delimited {{pspan|list}}, and returns the modified list.  If the entry already exists in the list, another entry will not be added.  For example, list_add(&amp;quot;a, b, c&amp;quot;,&amp;quot;d&amp;quot;) would return &amp;quot;a, b, c, d&amp;quot;, but list_add(&amp;quot;a, b, c&amp;quot;, &amp;quot;a&amp;quot;) would return &amp;quot;a, b, c&amp;quot;, since the entry &amp;quot;a&amp;quot; already exists.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|list_remove}}{{Function|&lt;br /&gt;
name=list_remove|&lt;br /&gt;
return_type=string|&lt;br /&gt;
parameter1={{Param|string|list}}|&lt;br /&gt;
parameter2={{Param|string|del}}|&lt;br /&gt;
}}&lt;br /&gt;
{{Function|&lt;br /&gt;
name=list_remove|&lt;br /&gt;
return_type=string|&lt;br /&gt;
parameter1={{Param|string|list}}|&lt;br /&gt;
parameter2={{Param|string|del}}|&lt;br /&gt;
parameter3={{Param|string|glue}}|&lt;br /&gt;
p1desc={{pspan|list}} is a glue-delimited string list such as returned by join() above.|&lt;br /&gt;
p2desc={{pspan|del}} is the entry to remove from the list.|&lt;br /&gt;
p3desc={{pspan|glue}} is optional (defaults to &amp;quot;, &amp;quot;) and represents the delimiter for the list.|&lt;br /&gt;
}}&lt;br /&gt;
Removes {{pspan|del}} from {{pspan|glue}}-delimited {{pspan|list}}, and returns the modified list.  It will remove all instances of {{pspan|del}}.  For example, list_remove(&amp;quot;a, b, c&amp;quot;,&amp;quot;a&amp;quot;) would return &amp;quot;b, c&amp;quot;, and list_remove(&amp;quot;a, a, b, b, c, c&amp;quot;, &amp;quot;a&amp;quot;) would return &amp;quot;b, b, c, c&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|rnum}}{{Function|&lt;br /&gt;
name=rnum|&lt;br /&gt;
return_type=string|&lt;br /&gt;
parameter1={{Param|int|n}}|&lt;br /&gt;
}}&lt;br /&gt;
{{Function|&lt;br /&gt;
name=rnum|&lt;br /&gt;
return_type=string|&lt;br /&gt;
parameter1={{Param|float|n}}|&lt;br /&gt;
}}&lt;br /&gt;
{{Function|&lt;br /&gt;
name=rnum|&lt;br /&gt;
return_type=string|&lt;br /&gt;
parameter1={{Param|float|n}}|&lt;br /&gt;
parameter2={{Param|int|place}}|&lt;br /&gt;
p1desc={{pspan|n}} is a number|&lt;br /&gt;
p2desc={{pspan|place}} is the number of decimal places to round to|&lt;br /&gt;
}}&lt;br /&gt;
Returns your number {{pspan|n}} as a human-readable string, appropriate to the user&#039;s computer&#039;s region. For ints, this means it adds grouping separators where appropriate. For floats, it also rounds to the nearest {{pspan|place}} after the decimal. Default {{pspan|place}} for the float-only version is 2, although it may display fewer digits if they are 0&#039;s. Examples: rnum(12580) =&amp;gt; &amp;quot;12,580&amp;quot;, rnum(3.14152964,3) =&amp;gt; &amp;quot;3.142&amp;quot;, rnum(4.00008) =&amp;gt; &amp;quot;4&amp;quot;, rnum(123456789.87654321) =&amp;gt; &amp;quot;123,456,789.88&amp;quot;.  Recommended as a substitute for to_string(int).&lt;br /&gt;
&lt;br /&gt;
== Number Functions ==&lt;br /&gt;
&lt;br /&gt;
{{HideLink|abs}}{{Function|&lt;br /&gt;
name=abs|&lt;br /&gt;
return_type=float|&lt;br /&gt;
parameter1={{Param|float|n}}|&lt;br /&gt;
p1desc={{pspan|n}} is any number.|&lt;br /&gt;
}}&lt;br /&gt;
Returns the absolute value of the number {{pspan|n}}.  Don&#039;t worry if you are working with integers, it will still work just fine.  This function already exists in many programming languages; ZLib makes it handily available in ASH.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|minmax}}{{Function|&lt;br /&gt;
name=minmax|&lt;br /&gt;
return_type=float|&lt;br /&gt;
parameter1={{Param|float|a}}|&lt;br /&gt;
parameter2={{Param|float|min}}|&lt;br /&gt;
parameter3={{Param|float|max}}|&lt;br /&gt;
p1desc={{pspan|a}} is the original number|&lt;br /&gt;
p2desc={{pspan|min}} is the minimum return value|&lt;br /&gt;
p3desc={{pspan|max}} is the maximum return value|&lt;br /&gt;
}}&lt;br /&gt;
Returns {{pspan|a}}, but no less than {{pspan|min}} and no more than {{pspan|max}}.  Another function common to many languages.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|set_avg}}{{Function|&lt;br /&gt;
name=set_avg|&lt;br /&gt;
return_type=void|&lt;br /&gt;
parameter1={{Param|float|to_add}}|&lt;br /&gt;
parameter2={{Param|string|which_prop}}|&lt;br /&gt;
p1desc={{pspan|to_add}} is the data point to add|&lt;br /&gt;
p2desc={{pspan|which_prop}} is the property to add data to|&lt;br /&gt;
}}&lt;br /&gt;
Useful for adding spading to scripts. Adds one more statistic to an average value being stored in a property. For example, calling this function three times with the values 2, 4, and 6 for {{pspan|to_add}} would result in the property {{pspan|which_prop}} containing &amp;quot;4.0:3&amp;quot;, with 4.0 being the average of the three numbers added and 3 being the amount of numbers averaged.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|get_avg}}{{Function|&lt;br /&gt;
name=get_avg|&lt;br /&gt;
return_type=float|&lt;br /&gt;
parameter1={{Param|string|which_prop}}|&lt;br /&gt;
p1desc={{pspan|which_prop}} is the property to access|&lt;br /&gt;
}}&lt;br /&gt;
Returns an average value set by set_avg().&lt;br /&gt;
&lt;br /&gt;
{{HideLink|eval}}{{Function|&lt;br /&gt;
name=eval|&lt;br /&gt;
return_type=float|&lt;br /&gt;
parameter1={{Param|string|expression}}|&lt;br /&gt;
parameter2={{Param|float [string]|values|ag=t}}|&lt;br /&gt;
p1desc={{pspan|expression}} is the base expression|&lt;br /&gt;
p2desc={{pspan|values}} is a map of values to replace|&lt;br /&gt;
}}&lt;br /&gt;
By Jason Harper. Evaluates {{pspan|expression}} as a math expression, and allows you to substitute {{pspan|values}} for variables, as described in much greater detail here. Brief documentation is also included in ZLib. (NB: This section needs more infoz.)&lt;br /&gt;
&lt;br /&gt;
== Script Functions ==&lt;br /&gt;
&lt;br /&gt;
{{HideLink|check_version}}{{Function|&lt;br /&gt;
name=check_version|&lt;br /&gt;
return_type=string|&lt;br /&gt;
parameter1={{Param|string|soft}}|&lt;br /&gt;
parameter2={{Param|string|proj}}|&lt;br /&gt;
parameter3={{Param|int|thread}}|&lt;br /&gt;
p1desc={{pspan|soft}} is the script name, which must match the page source of the {{pspan|thread}} being parsed|&lt;br /&gt;
p2desc={{pspan|proj}} is the name of the SVN project name to check.|&lt;br /&gt;
p3desc={{pspan|thread}} is the script&#039;s thread number on kolmafia.us|&lt;br /&gt;
}}&lt;br /&gt;
{{Function|&lt;br /&gt;
name=check_version|&lt;br /&gt;
return_type=string|&lt;br /&gt;
parameter1={{Param|string|soft}}|&lt;br /&gt;
parameter2={{Param|string|prop}}|&lt;br /&gt;
parameter3={{Param|string|this_version}}|&lt;br /&gt;
parameter4={{Param|int|thread}}|&lt;br /&gt;
p1desc={{pspan|soft}} is as above.|&lt;br /&gt;
p2desc={{pspan|prop}} is used as part of the name of the property saved to user preferences.|&lt;br /&gt;
p3desc={{pspan|this_version}} is the version of the script currently running|&lt;br /&gt;
p4desc={{pspan|thread}} is as above.|&lt;br /&gt;
}}&lt;br /&gt;
Server-friendly once-daily version-checking.  There are two versions of this function, one for SVN and one for forum threads.  The three-parameter SVN version uses mafia&#039;s SVN client to check if a previously checked-out SVN project is current and if not, it updates it automatically, meaning the script will be current the next time it runs.  In the event that a user has checked the option for mafia to automatically update all projects on login, it detects that the script has updated and prints an informative message with a link to the script&#039;s kolmafia.us thread -- and if the project is hosted on SourceForge, an additional link to the changelog there.&lt;br /&gt;
&lt;br /&gt;
For the four-parameter forum thread version, it visits the specified {{pspan|thread}} on the kolmafia.us forums to find the current version of your script. The thread must include &amp;lt;nowiki&amp;gt;&amp;quot;&amp;lt;b&amp;gt;&amp;lt;/nowiki&amp;gt;{{pspan|soft}} {{pspan|version}}&amp;lt;nowiki&amp;gt;&amp;lt;/b&amp;gt;&amp;quot;&amp;lt;/nowiki&amp;gt; for the version info to be successfully parsed. Optionally, you may include &amp;lt;nowiki&amp;gt;&amp;quot;[requires revision XXXX]&amp;quot;&amp;lt;/nowiki&amp;gt; somewhere in your post if you want to indicate a required minimum revision of mafia. If a new version is available, it alerts the user in large text and provides an update link.&lt;br /&gt;
&lt;br /&gt;
The return value of both versions is a blank string unless an update is/was found, in which case it is a &amp;lt;nowiki&amp;gt;&amp;lt;div class=&#039;versioninfo&#039;&amp;gt;&amp;lt;/nowiki&amp;gt; containing the update message. This allows this function to work equally well for relay scripts. The current version/revision (and the last date checked) is stored in a data file &amp;quot;zversions.txt&amp;quot;.  Example:&lt;br /&gt;
{{CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
check_version(&amp;quot;Hardcore Checklist&amp;quot;,&amp;quot;checklist&amp;quot;,&amp;quot;1.2.7&amp;quot;,1045);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{HideLink|load_current_map}}{{Function|&lt;br /&gt;
name=load_current_map|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|string|map_name}}|&lt;br /&gt;
parameter2={{Param|aggregate|destination}}|&lt;br /&gt;
p1desc={{pspan|map_name}} is the name of the map, without the file extension|&lt;br /&gt;
p2desc={{pspan|destination}} is a previously-declared map to load with data|&lt;br /&gt;
}}&lt;br /&gt;
Acts as a wrapper for the built-in {{f|file_to_map}} with automatic update capability. The first time the function is called for a given map each day, it will check [http://zachbardon.com/mafiatools/autoupdate.php Zarqon&#039;s Map Manager] to see if an update for the given {{pspan|map_name}} is available, and if so will load from there. Otherwise, it merely loads it from disk. (Note: you should not include a file extension, such as &amp;quot;.txt&amp;quot; in the {{pspan|map_name}} parameter.)&lt;br /&gt;
&lt;br /&gt;
{{HideLink|setvar}}{{Function|&lt;br /&gt;
name=setvar|&lt;br /&gt;
return_type=void|&lt;br /&gt;
parameter1={{Param|string|name}}|&lt;br /&gt;
parameter2={{Param|mixed|dfault}}|&lt;br /&gt;
p1desc={{pspan|name}} is the name of the setting|&lt;br /&gt;
p1desc={{pspan|dfault}} can be any primitive or ASH type (e.g. item, effect, coinmaster, etc.), but not an array, map, or record.|&lt;br /&gt;
}}&lt;br /&gt;
This function ensures that a ZLib script setting called {{pspan|name}} exists.  If not, it creates it and sets it to {{pspan|dfault}}.  If the setting already exists, it normalizes it to the same type as {{pspan|dfault}}, but otherwise does nothing.  Note that this function is for initializing settings, not for editing existing settings.  That is done by calling ZLib in the CLI.&lt;br /&gt;
&lt;br /&gt;
==== For Users ====&lt;br /&gt;
&lt;br /&gt;
* Script settings are now all saved in one place, separate from mafia properties. I&#039;ve read more than one post wishing that script-defined settings and mafia properties would be separate. This provides a solution.&lt;br /&gt;
* Script settings are independent from scripts. This means that you will no longer need to edit scripts to adjust your settings. Further, when you download a script update, the script will still use your saved settings and you won&#039;t need to reset them!&lt;br /&gt;
* To see all of your current settings, type &amp;quot;zlib vars&amp;quot; in the CLI. You can also type &amp;quot;zlib &amp;lt;whatever&amp;gt;&amp;quot; to see a list of current settings and values containing &amp;lt;whatever&amp;gt;.  To change a setting, type &amp;quot;zlib settingname = value&amp;quot;. If you&#039;re adjusting threshold, you can use &amp;quot;up&amp;quot; or &amp;quot;down&amp;quot; as the value to adjust your threshold relatively. This is almost exactly as convenient as mafia settings (possibly more so since you don&#039;t need to open a text file to find setting names!).&lt;br /&gt;
* If for some reason you prefer to open a text file, ZLib settings are stored in a file called vars_myname.txt in your data directory.&lt;br /&gt;
* Scripts that use Zlib script settings will only create these settings when you run them for the first time.  Attempting to edit a nonexisting setting won&#039;t work, so you&#039;ll need to run a script once (then, usually, mash the ESC key before it actually does anything) before you can configure it.  Script documentation should tell you which settings to change to get your desired behavior.&lt;br /&gt;
&lt;br /&gt;
==== For Script Authors ====&lt;br /&gt;
&lt;br /&gt;
* Script settings may now be used across scripts, in exactly the same way that mafia properties are. Basically, this works almost exactly like mafia properties, except that new settings can only be created by setvar() or manually editing the file (&amp;quot;zlib nonexistentsetting = value&amp;quot; will fail).&lt;br /&gt;
* Settings are only stored if you run a script that defines/uses them. So your settings file will not contain any extraneous unused settings.&lt;br /&gt;
* Script authors can now test for a setting&#039;s existence, which means you can check to see if a user has used a given script. It&#039;s almost as good as a script_exists() function. This can allow scripts to work together with other scripts, if they exist!&lt;br /&gt;
* Scripts with overlapping or related functionality can be designed to access a single shared setting, in much the same way that my scripts have until now all shared a &amp;quot;threshold&amp;quot; mafia setting. Changing a single setting can now change the behavior of every script that accesses that setting.&lt;br /&gt;
&lt;br /&gt;
==== Functional Details ====&lt;br /&gt;
&lt;br /&gt;
When importing ZLib, it loads a map of your script settings from vars_myname.txt. It is a basic string[string] map called vars. To access a script setting within an ASH script, use vars[varname]. To check if a setting exists you can simply use if (vars contains varname).&lt;br /&gt;
&lt;br /&gt;
When a script calls setvar(&amp;quot;threshold&amp;quot;,4), ZLib checks to see if a variable called &amp;quot;threshold&amp;quot; already exists in vars. If so, since dfault is an integer, it ensures that the value is an integer using normalize() (saving changes if necessary), but unless normalization changed the value, nothing else happens.  If &amp;quot;threshold&amp;quot; does not exist in vars, it creates it, sets it to 4, and saves the updated map back to vars_myname.txt.&lt;br /&gt;
&lt;br /&gt;
==== Choosing Setting Names ====&lt;br /&gt;
&lt;br /&gt;
The file of script settings will contain all script settings, sorted alphabetically. Also, there is no way to detect if a setting is unused, so if you decide to change the name, the old setting will never be deleted. &#039;&#039;&#039;Please think carefully about your setting names.&#039;&#039;&#039; If you have a setting named &amp;quot;setting1&amp;quot;, a user will probably not have a clue which script that is for or what it does. True, this can be overcome with documentation, but it is far better to have settings that make sense just by looking at them.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Recommendations:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
1. Use a name that clearly identifies what the setting is/does.&lt;br /&gt;
&lt;br /&gt;
2. Prefix your setting names with a script identifier. For example, here are some of my One-Click Wossname script settings:&lt;br /&gt;
&lt;br /&gt;
{{CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
setvar(&amp;quot;ocw_warplan&amp;quot;,&amp;quot;optimal&amp;quot;);&lt;br /&gt;
setvar(&amp;quot;ocw_change_to_meat&amp;quot;,true);&lt;br /&gt;
setvar(&amp;quot;ocw_nunspeed&amp;quot;,false);&lt;br /&gt;
setvar(&amp;quot;defaultoutfit&amp;quot;,&amp;quot;current&amp;quot;);&lt;br /&gt;
setvar(&amp;quot;ocw_f_default&amp;quot;,&amp;quot;zombie&amp;quot;);&lt;br /&gt;
setvar(&amp;quot;ocw_m_default&amp;quot;,&amp;quot;&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
Those settings which are specific to OCW are prefixed with &amp;quot;ocw_&amp;quot; so as to be found together in the settings file. However, some of the settings are usable across scripts, and are not so prefixed. For example, the &amp;quot;defaultoutfit&amp;quot; will be used by nearly all of my adventuring scripts that swap outfits, so no prefix is given.&lt;br /&gt;
&lt;br /&gt;
== Adventuring Functions ==&lt;br /&gt;
&lt;br /&gt;
{{HideLink|be_good}}{{Function|&lt;br /&gt;
name=be_good|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|string|johnny}}|&lt;br /&gt;
p1desc={{pspan|johnny}} is the thing you want to check -- usually an item or familiar|&lt;br /&gt;
}}&lt;br /&gt;
This function, originally created to check whether items were allowed in the Bees Hate You path, has been expanded to an all-purpose check to see whether something is acceptable in your current path.  For example, in a Trendy path, outdated items would not be_good.  Likewise, during Bees Hate You, a familiar containing a &#039;b&#039; would not be_good.  In Fistcore, anything you hold in your hands is not allowed.  And so forth.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|mall_val}}{{Function|&lt;br /&gt;
name=mall_val|&lt;br /&gt;
return_type=int|&lt;br /&gt;
parameter1={{Param|item|it}}|&lt;br /&gt;
parameter2={{Param|float|expirydays}}|&lt;br /&gt;
parameter3={{Param|boolean|combatsafe}}|&lt;br /&gt;
p1desc={{pspan|it}} is the item being valued.|&lt;br /&gt;
p2desc={{pspan|expirydays}} is optional, default 0.  It represents the age at which {{f|historical_price}} is no longer valid, after which {{f|mall_price}} is used.|&lt;br /&gt;
p3desc={{pspan|combatsafe}} is optional, default false. If true, the function will avoid calling mall_price and use only historical_price, regardless of age.|&lt;br /&gt;
}}&lt;br /&gt;
The ASH functions {{f|mall_price}}, {{f|historical_price}}, and {{f|historical_age}} are often combined to save server hits when checking for the price of multiple items.  Scripts will use the historical price if it is fairly recent, or hit the server with mall_price if it is too old.  This function wraps all of that up, and even adds a flag for getting item values during combat (when you don&#039;t have mall access).  You&#039;ll generally call this with only one of the two parameters.&lt;br /&gt;
&lt;br /&gt;
If you want to only use historical_price: mall_val(someitem, true)&lt;br /&gt;
If you want to only use mall price: mall_val(someitem,0)&lt;br /&gt;
If you want to use historical prices no more than 2 days old, otherwise use mall price: mall_val(someitem,3)&lt;br /&gt;
&lt;br /&gt;
{{HideLink|sell_val}}{{Function|&lt;br /&gt;
name=sell_val|&lt;br /&gt;
return_type=int|&lt;br /&gt;
parameter1={{Param|item|it}}|&lt;br /&gt;
parameter2={{Param|float|expirydays}}|&lt;br /&gt;
parameter3={{Param|boolean|combatsafe}}|&lt;br /&gt;
p1desc={{pspan|it}} is the item being valued.|&lt;br /&gt;
p2desc={{pspan|expirydays}} is the same as in mall_val() above.|&lt;br /&gt;
p3desc={{pspan|combatsafe}} is also as in mall_val() above.|&lt;br /&gt;
}}&lt;br /&gt;
This function is concerned with the meat you could realistically expect to get from selling the item.  It returns mall_val, unless the mall value is at minimum, meaning it&#039;s junk which probably won&#039;t sell.  In that case it returns the item&#039;s autosell value.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|tower_items}}{{Function|&lt;br /&gt;
name=tower_items|&lt;br /&gt;
aggregate=true|&lt;br /&gt;
return_type=boolean [string]|&lt;br /&gt;
}}&lt;br /&gt;
{{Function|&lt;br /&gt;
name=tower_items|&lt;br /&gt;
aggregate=true|&lt;br /&gt;
return_type=boolean [string]|&lt;br /&gt;
parameter1={{Param|boolean|combat_safe}}|&lt;br /&gt;
p1desc={{pspan|combat_safe}} is optional.  Supply it as true if you are in combat.|&lt;br /&gt;
}}&lt;br /&gt;
This handy function returns a map of the items you definitely need (value: true) or might need (value: false) to pass the entryway and climb the tower.  You can check (tower_items() contains X) to determine whether an item has a nonzero chance of being required for the tower, or check tower_items(X) to determine whether an item has a 100% chance of being needed (i.e. it was indicated necessary by your telescope).  If you haven&#039;t yet checked your telescope yet this run, it will also do that to populate the relevant mafia properties, unless you have supplied the optional {{pspan|combat_safe}} parameter as true (you can&#039;t access your telescope during combat).&lt;br /&gt;
&lt;br /&gt;
{{HideLink|have_item}}{{Function|&lt;br /&gt;
name=have_item|&lt;br /&gt;
return_type=int|&lt;br /&gt;
parameter1={{Param|string|to_lookup}}|&lt;br /&gt;
p1desc={{pspan|to_lookup}} is the item to count|&lt;br /&gt;
}}&lt;br /&gt;
A residual function, used by the following and probably in several other scripts. Returns the amount of an item you have both in your inventory and equipped. Similar but not equivalent to the ASH function {{f|available_amount}}, since this function completely ignores your closet and storage.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|is_goal}}{{Function|&lt;br /&gt;
name=is_goal|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|stat|whichstat}}|&lt;br /&gt;
p1desc={{pspan|whichstat}} is the stat to check|&lt;br /&gt;
}}&lt;br /&gt;
The ASH function {{f|is_goal}} takes an item parameter and returns true if the given item is a goal.  ZLib extends that function by also including a version which accepts a stat as a parameter.  Stats can be goals when a user or script sets &amp;quot;level X&amp;quot; or &amp;quot;X muscle&amp;quot; as a goal.  Additionally, the function treats your primestat as a permanent goal until you are level 13.  So for both a level 9 Sauceror or a level 10 Seal Clubber who set &amp;quot;200 mysticality&amp;quot; as a goal, is_goal($stat[mysticality]) would return true.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|isxpartof}}{{Function|&lt;br /&gt;
name=isxpartof|&lt;br /&gt;
return_type=float|&lt;br /&gt;
parameter1={{Param|item|child}}|&lt;br /&gt;
parameter2={{Param|item|ancestor}}|&lt;br /&gt;
p1desc={{pspan|child}} is the ingredient/component you want to check.|&lt;br /&gt;
p2desc={{pspan|ancestor}} is the concoction you want to check.|&lt;br /&gt;
}}&lt;br /&gt;
In the sentence &amp;quot;child is X part of ancestor&amp;quot;, this function returns X.  It assumes the minimum amount of other ingredients necessary.  For example, isxpartof($item[white pixel], $item[digital key]) returns 0.033333335 (1/30), since 30 white pixels are needed to make a digital key.  However, isxpartof($item[red pixel], $item[digital key]) returns 0.03125 (1/32), assuming 1 each of green and blue pixels and 29 other white pixels (rather than 30 each RGB pixels -- 1/90).  This function is used by has_goal(item) but may have uses in your own script.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|has_goal}}{{Function|&lt;br /&gt;
name=has_goal|&lt;br /&gt;
return_type=float|&lt;br /&gt;
parameter1={{Param|item|check_me}}|&lt;br /&gt;
}}&lt;br /&gt;
{{Function|&lt;br /&gt;
name=has_goal|&lt;br /&gt;
return_type=float|&lt;br /&gt;
parameter1={{Param|monster|check_me}}|&lt;br /&gt;
}}&lt;br /&gt;
{{Function|&lt;br /&gt;
name=has_goal|&lt;br /&gt;
return_type=float|&lt;br /&gt;
parameter1={{Param|location|check_me}}|&lt;br /&gt;
p1desc={{pspan|check_me}} is the item, monster or locationto check|&lt;br /&gt;
}}&lt;br /&gt;
At the base of this function is the item parameter version, which returns the chance that the item {{pspan|check_me}} is or results in a goal. If the item is itself a goal, returns 1.0. Otherwise, returns what percentage of a goal the item is, which could be nonzero in two cases: 1) you could get a goal by using the item (returns the chance of success), or 2) the item is an ingredient of a goal.  For example, with a goal of black pepper, has_goal($item[black picnic basket]) would return 0.58.&lt;br /&gt;
&lt;br /&gt;
When supplied a monster as the parameter for {{pspan|check_me}}, returns the percent chance that encountering the given monster will result in a goal, taking into account +items, pickpocket availability (and +pickpocket), and Torso. For instance, with no +item and black pepper as a goal, has_goal($monster[black widow]) would return 0.087 (0.58 basket contains pepper * 0.15 basket drop rate). Also note that it will add multiple goals together, so with white pixels as a goal, a Blooper would return 2.1.&lt;br /&gt;
&lt;br /&gt;
When supplied a location as the parameter for {{pspan|check_me}}, returns the chance that adventuring at a given location will yield a goal. For our black pepper example, has_goal($location[black forest]) would return 0.0174 (0.2 black widow appearance rate * 0.087 chance that a widow has black pepper). Presently this accounts for combat frequency modifiers but not Olfaction, and it will be off for areas with noncombats that grant goals, because it assumes that all noncombats do not yield items.&lt;br /&gt;
&lt;br /&gt;
These functions also have an optional boolean parameter, usespec.  If supplied as true, these functions will use speculative values.  (See &amp;quot;whatif&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
{{HideLink|obtain}}{{Function|&lt;br /&gt;
name=obtain|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|int|qty}}|&lt;br /&gt;
parameter2={{Param|string|condition}}|&lt;br /&gt;
parameter3={{Param|location|place}}|&lt;br /&gt;
}}&lt;br /&gt;
{{Function|&lt;br /&gt;
name=obtain|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|int|qty}}|&lt;br /&gt;
parameter2={{Param|string|condition}}|&lt;br /&gt;
parameter3={{Param|location|place}}|&lt;br /&gt;
parameter4={{Param|string|filter}}|&lt;br /&gt;
p1desc={{pspan|qty}} is the quantity of the item or choice adventure desired|&lt;br /&gt;
p2desc={{pspan|condition}} is the item or choice adventure to use as a goal|&lt;br /&gt;
p3desc={{pspan|place}} is the location to adventure to obtain your goal|&lt;br /&gt;
p4desc={{pspan|filter}} is an optional combat filter used the same as in {{f|adventure}}|&lt;br /&gt;
}}&lt;br /&gt;
Attempts to get {{pspan|qty}} (minus existing) of {{pspan|condition}}, either by purchasing (if you have the KoLmafia preference set), pulling from Hangk&#039;s, or adventuring at the specified {{pspan|place}}. It also works with choice adventures.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|use_upto}}{{Function|&lt;br /&gt;
name=use_upto|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|int|qty}}|&lt;br /&gt;
parameter2={{Param|item|thing}}|&lt;br /&gt;
parameter3={{Param|boolean|purchase}}|&lt;br /&gt;
p1desc={{pspan|qty}} is the quantity to use|&lt;br /&gt;
p2desc={{pspan|thing}} is the item to use|&lt;br /&gt;
p3desc={{pspan|purchase}} is true if KoLmafia should purchase extras if you don&#039;t already have {{pspan|qty}}|&lt;br /&gt;
}}&lt;br /&gt;
Gets (if purchase is true) and uses {{pspan|qty}} of the item(s) {{pspan|thing}} if possible. Otherwise, uses as many as you have up to {{pspan|qty}}.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|resist}}{{Function|&lt;br /&gt;
name=resist|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|element|resist_it}}|&lt;br /&gt;
parameter2={{Param|boolean|really}}|&lt;br /&gt;
p1desc={{pspan|resist_it}} is the element to resist|&lt;br /&gt;
p2desc={{pspan|really}} is true to actually attemp resistance, false to check only|&lt;br /&gt;
}}&lt;br /&gt;
Returns whether you are able to resist a given element {{pspan|resist_it}}, or if {{pspan|really}} is true, attempts to actually achieve that resistance (casting buffs, changing gear, or equipping your Exotic Parrot) and returns its success.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|my_defstat}}{{Function|&lt;br /&gt;
name=my_defstat|&lt;br /&gt;
return_type=int|&lt;br /&gt;
parameter1={{Param|boolean|usespec}}|&lt;br /&gt;
p1desc={{pspan|usespec}} is optional.  If true, uses speculative values rather than real values.|&lt;br /&gt;
}}&lt;br /&gt;
Returns the value of your buffed defense stat, taking into account Hero of the Half-Shell.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|get_safemox}}{{Function|&lt;br /&gt;
name=get_safemox|&lt;br /&gt;
return_type=int|&lt;br /&gt;
parameter1={{Param|location|where}}|&lt;br /&gt;
p1desc={{pspan|where}} is the location to check for safe moxie|&lt;br /&gt;
}}&lt;br /&gt;
Using mafia&#039;s location/monster data, returns the safe moxie of a given zone {{pspan|where}}.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|auto_mcd}}{{Function|&lt;br /&gt;
name=auto_mcd|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|int|check_me}}|&lt;br /&gt;
}}&lt;br /&gt;
{{Function|&lt;br /&gt;
name=auto_mcd|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|monster|check_me}}|&lt;br /&gt;
}}&lt;br /&gt;
{{Function|&lt;br /&gt;
name=auto_mcd|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|location|check_me}}|&lt;br /&gt;
p1desc={{pspan|check_me}} is the int, monster or location to check|&lt;br /&gt;
}}&lt;br /&gt;
If your ZLib setting &amp;quot;automcd&amp;quot; is true, automatically adjusts your mind-control device for maximum stat gains based on safe moxie and your ZLib &amp;quot;threshold&amp;quot; setting. Does not adjust for MCD-sensitive areas (certain bosses, Slime Tube), or areas with no known combats. Returns true unless KoLmafia is unable to do so, even though the script thinks it should be capable (still returns true if you can&#039;t currently access an mcd-changing device).&lt;br /&gt;
&lt;br /&gt;
{{HideLink|best_fam}}{{Function|&lt;br /&gt;
name=best_fam|&lt;br /&gt;
return_type=familiar|&lt;br /&gt;
parameter1={{Param|string|type}}|&lt;br /&gt;
p1desc={{pspan|type}} is the type of familiar ability to check for|&lt;br /&gt;
}}&lt;br /&gt;
Returns your heaviest familiar of a given type (currently possible: items, meat, produce, stat, delevel). If your ZLib &amp;quot;is_100_run&amp;quot; setting is anything other than $familiar[none], returns that familiar (so you don&#039;t have to make the check in your script).&lt;br /&gt;
&lt;br /&gt;
== Kmail Functions ==&lt;br /&gt;
&lt;br /&gt;
{{HideLink|load_kmail}}{{Function|&lt;br /&gt;
name=load_kmail|&lt;br /&gt;
return_type=void|&lt;br /&gt;
parameter1={{Param|string|calledby}}|&lt;br /&gt;
p1desc={{pspan|calledby}} is optional and allows you to specify the name of the script calling this function, which will be submitted when the script visits api.php. The default value is &amp;quot;ZLib-powered-script&amp;quot;.|&lt;br /&gt;
}}&lt;br /&gt;
This function parses your kmail inbox in a single server hit and loads it into the global variable &amp;quot;mail&amp;quot;, which is of type kmessage[int].  A kmessage is a record type, with the following fields:&lt;br /&gt;
{{CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
record kmessage {&lt;br /&gt;
   int id;                   // message id&lt;br /&gt;
   string type;              // possible values observed thus far: normal, giftshop&lt;br /&gt;
   int fromid;               // sender&#039;s playerid (0 for npc&#039;s)&lt;br /&gt;
   int azunixtime;           // KoL server&#039;s unix timestamp&lt;br /&gt;
   string message;           // message (not including items/meat)&lt;br /&gt;
   int[item] items;          // items included in the message&lt;br /&gt;
   int meat;                 // meat included in the message&lt;br /&gt;
   string fromname;          // sender&#039;s playername&lt;br /&gt;
   string localtime;         // your local time according to your KoL account, human-readable string&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Thus, after calling this function your inbox is very easy to work with.  You can foreach over each message if you like, accessing the fields for details.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|process_kmail}}{{Function|&lt;br /&gt;
name=process_kmail|&lt;br /&gt;
return_type=void|&lt;br /&gt;
parameter1={{Param|string|functionname}}|&lt;br /&gt;
p1desc={{pspan|functionname}} specifies the name of a function designed to parse kmail.|&lt;br /&gt;
}}&lt;br /&gt;
If you liked load_kmail(), you&#039;ll like this even better.  First off, this function loads your kmail into the mail variable if you haven&#039;t already done so.  Next, it calls a function named {{pspan|functionname}} on each kmail message.  The function must be at top level, accept a single kmessage parameter, and return a boolean.  For each kmail in your inbox, if the called function returns true, that message will be deleted once all messages have been processed.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a simple example which will delete all messages from your lovely Pen Pal:&lt;br /&gt;
{{CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
boolean no_penpal(kmessage m) {&lt;br /&gt;
   if (m.fromname == &amp;quot;Your Pen Pal&amp;quot;) return true;&lt;br /&gt;
   return false;&lt;br /&gt;
}&lt;br /&gt;
process_kmail(&amp;quot;no_penpal&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{HideLink|send_gift}}{{Function|&lt;br /&gt;
name=send_gift|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|string|recipient}}|&lt;br /&gt;
parameter2={{Param|string|message}}|&lt;br /&gt;
parameter3={{Param|int|meat}}|&lt;br /&gt;
parameter4={{Param|int [item]|goodies|ag=t}}|&lt;br /&gt;
}}&lt;br /&gt;
{{Function|&lt;br /&gt;
name=send_gift|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|string|recipient}}|&lt;br /&gt;
parameter2={{Param|string|message}}|&lt;br /&gt;
parameter3={{Param|int|meat}}|&lt;br /&gt;
parameter4={{Param|int [item]|goodies|ag=t}}|&lt;br /&gt;
parameter5={{Param|string|inside_note}}|&lt;br /&gt;
p1desc={{pspan|recipient}} is the player to send to|&lt;br /&gt;
p2desc={{pspan|message}} is the outside message|&lt;br /&gt;
p3desc={{pspan|meat}} is the amount of meat to send|&lt;br /&gt;
p4desc={{pspan|goodies}} is a map of items &amp;amp; amounts to send|&lt;br /&gt;
p5desc={{pspan|inside_note}} is an optional inside message|&lt;br /&gt;
}}&lt;br /&gt;
Sends a gift to a player. Able to split large amounts of items. Returns true if the package is sent and false if not. See kmail() below.&lt;br /&gt;
&lt;br /&gt;
{{HideLink|kmail}}{{Function|&lt;br /&gt;
name=kmail|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|string|recipient}}|&lt;br /&gt;
parameter2={{Param|string|message}}|&lt;br /&gt;
parameter3={{Param|int|meat}}|&lt;br /&gt;
}}&lt;br /&gt;
{{Function|&lt;br /&gt;
name=kmail|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|string|recipient}}|&lt;br /&gt;
parameter2={{Param|string|message}}|&lt;br /&gt;
parameter3={{Param|int|meat}}|&lt;br /&gt;
parameter4={{Param|int [item]|goodies|ag=t}}|&lt;br /&gt;
}}&lt;br /&gt;
{{Function|&lt;br /&gt;
name=kmail|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|string|recipient}}|&lt;br /&gt;
parameter2={{Param|string|message}}|&lt;br /&gt;
parameter3={{Param|int|meat}}|&lt;br /&gt;
parameter4={{Param|int [item]|goodies|ag=t}}|&lt;br /&gt;
parameter5={{Param|string|inside_note}}|&lt;br /&gt;
p1desc={{pspan|recipient}} is the player to send to|&lt;br /&gt;
p2desc={{pspan|message}} is the outside message|&lt;br /&gt;
p3desc={{pspan|meat}} is the amount of meat to send|&lt;br /&gt;
p4desc={{pspan|goodies}} is an optional map of items &amp;amp; amounts to send|&lt;br /&gt;
p5desc={{pspan|inside_note}} is an optional inside message if sent as a gift|&lt;br /&gt;
}}&lt;br /&gt;
{{Function|&lt;br /&gt;
name=kmail|&lt;br /&gt;
return_type=boolean|&lt;br /&gt;
parameter1={{Param|kmessage|km}}|&lt;br /&gt;
p1desc={{pspan|km}} allows you to send a kmail supplied in kmessage format.  The only thing unusual here is that the &amp;quot;fromname&amp;quot; field will be used as the recipient.  The other fields will be used appropriately to call the above kmail function.|&lt;br /&gt;
}}&lt;br /&gt;
Sends a kmail to player {{pspan|recipient}}, returning true if the kmail is successfully sent. Handles splitting the {{pspan|message}} into multiple messages if the number of item types in {{pspan|goodies}} is too large. Returns the result of send_gift() if the intended {{pspan|recipient}} is unable to receive the {{pspan|message}} due to being in HC or somesuch. Note that you can also specify the {{pspan|inside_note}} to be used inside gifts in that case. Use &amp;quot;\n&amp;quot; to specify a new line in the {{pspan|message}}.&lt;br /&gt;
&lt;br /&gt;
== More Information ==&lt;br /&gt;
&amp;lt;p&amp;gt;See the thread for ZLib on the mafia forum [http://kolmafia.us/showthread.php?2072 here].&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting]][[Category:ASH Function Libraries]]&lt;/div&gt;</summary>
		<author><name>PsyMar</name></author>
	</entry>
	<entry>
		<id>https://wiki.kolmafia.us/index.php?title=Ash_Functions&amp;diff=2585</id>
		<title>Ash Functions</title>
		<link rel="alternate" type="text/html" href="https://wiki.kolmafia.us/index.php?title=Ash_Functions&amp;diff=2585"/>
		<updated>2013-06-30T21:31:01Z</updated>

		<summary type="html">&lt;p&gt;PsyMar: /* d */ redlink to dad_sea_monkee_weakness&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{TOCright}}&lt;br /&gt;
Master list of all ASH functions. All functions as of r8144 are listed; this list is intended to be kept current, but it is possible that some functions added since the above revision may be missing. (Please feel free to add in any you notice.)&lt;br /&gt;
===a===&lt;br /&gt;
{{Flink|void|abort|{{opt|string}}}}&lt;br /&gt;
{{Flink|void|add_item_condition|int|item}}&lt;br /&gt;
{{Flink|boolean|adv1|location|int|string}}&lt;br /&gt;
{{Flink|boolean|adventure|int|location|{{opt|string}}}}&lt;br /&gt;
{{Flink|float [monster]|appearance_rates|location|{{opt|boolean}}}}&lt;br /&gt;
{{Flink|buffer|append|buffer|string}}&lt;br /&gt;
{{Flink|buffer|append_replacement|matcher|buffer|string}}&lt;br /&gt;
{{Flink|buffer|append_tail|matcher|buffer}}&lt;br /&gt;
{{Flink|buffer|attack}}&lt;br /&gt;
{{Flink|boolean|autosell|int|item}}&lt;br /&gt;
{{Flink|int|autosell_price|item}}&lt;br /&gt;
{{Flink|int|available_amount|item}}&lt;br /&gt;
===b===&lt;br /&gt;
{{Flink|boolean|batch_close}}&lt;br /&gt;
{{Flink|void|batch_open}}&lt;br /&gt;
{{Flink|boolean|black_market_available}}&lt;br /&gt;
{{Flink|boolean|boolean_modifier|string|{{opt|string}}}}&lt;br /&gt;
{{Flink|boolean|boolean_modifier|item|string}}&lt;br /&gt;
{{Flink|int|buffed_hit_stat}}&lt;br /&gt;
{{Flink|boolean|buy|int|item}}&lt;br /&gt;
{{Flink|int|buy|int|item|int}}&lt;br /&gt;
{{Flink|boolean|buy|coinmaster|int|item}}&lt;br /&gt;
{{Flink|int|buy_price|coinmaster|item}}&lt;br /&gt;
{{Flink|boolean|buys_item|coinmaster|item}}&lt;br /&gt;
===c===&lt;br /&gt;
{{Flink|boolean|can_drink}}&lt;br /&gt;
{{Flink|boolean|can_eat}}&lt;br /&gt;
{{Flink|boolean|can_equip|item}}&lt;br /&gt;
{{Flink|boolean|can_interact}}&lt;br /&gt;
{{flink|boolean|canadia_available}}&lt;br /&gt;
{{Flink|int|ceil|float}}&lt;br /&gt;
{{Flink|boolean|chamber}}&lt;br /&gt;
{{Flink|boolean|change_mcd|int}}&lt;br /&gt;
{{Flink|string|char_at|string|int}}&lt;br /&gt;
{{Flink|void|chat_clan|string|{{opt|string}}}}&lt;br /&gt;
{{Flink|void|chat_macro|string}}&lt;br /&gt;
{{Flink|void|chat_notify|string|string}}&lt;br /&gt;
{{Flink|void|chat_private|string|string}}&lt;br /&gt;
{{Flink|class|class_modifier|string|string}}&lt;br /&gt;
{{Flink|class|class_modifier|item|string}}&lt;br /&gt;
{{Flink|void|clear|aggregate}}&lt;br /&gt;
{{Flink|boolean|cli_execute|string}}&lt;br /&gt;
{{Flink|int|closet_amount|item}}&lt;br /&gt;
{{Flink|int|combat_mana_cost_modifier}}&lt;br /&gt;
{{Flink|float|combat_rate_modifier}}&lt;br /&gt;
{{Flink|boolean|contains_text|string|string}}&lt;br /&gt;
{{Flink|void|council}}&lt;br /&gt;
{{Flink|int|count|aggregate}}&lt;br /&gt;
{{Flink|boolean|craft|string|int|item|item}}&lt;br /&gt;
{{Flink|int|creatable_amount|item}}&lt;br /&gt;
{{Flink|boolean|create|int|item}}&lt;br /&gt;
{{Flink|matcher|create_matcher|string|string}}&lt;br /&gt;
{{Flink|stat|current_hit_stat}}&lt;br /&gt;
{{Flink|int|current_mcd}}&lt;br /&gt;
&lt;br /&gt;
===d===&lt;br /&gt;
{{Flink|element|dad_sea_monkee_weakness|int}}&lt;br /&gt;
{{Flink|item|daily_special}}&lt;br /&gt;
{{Flink|float|damage_absorption_percent}}&lt;br /&gt;
{{Flink|int|damage_reduction}}&lt;br /&gt;
{{Flink|buffer|delete|buffer|int|int}}&lt;br /&gt;
{{Flink|void|disable|string}}&lt;br /&gt;
{{flink|boolean|dispensary_available}}&lt;br /&gt;
{{Flink|int|display_amount|item}}&lt;br /&gt;
{{Flink|boolean|drink|int|item}}&lt;br /&gt;
&lt;br /&gt;
===e===&lt;br /&gt;
{{Flink|boolean|eat|int|item}}&lt;br /&gt;
{{Flink|boolean|eatsilent|int|item}}&lt;br /&gt;
{{Flink|effect|effect_modifier|string|string}}&lt;br /&gt;
{{Flink|effect|effect_modifier|item|string}}&lt;br /&gt;
{{Flink|float|elemental_resistance|element}}&lt;br /&gt;
{{Flink|float|elemental_resistance|{{opt|monster}}}}&lt;br /&gt;
{{Flink|boolean|empty_closet}}&lt;br /&gt;
{{Flink|void|enable|string}}&lt;br /&gt;
{{Flink|int|end|matcher|{{opt|int}}}}&lt;br /&gt;
{{Flink|boolean|enthrone_familiar|familiar}}&lt;br /&gt;
{{Flink|string|entity_decode|string}}&lt;br /&gt;
{{Flink|string|entity_encode|string}}&lt;br /&gt;
{{Flink|boolean|entryway}}&lt;br /&gt;
{{Flink|boolean|equip|{{opt|slot}}|item}}&lt;br /&gt;
{{Flink|int|equipped_amount|item}}&lt;br /&gt;
{{Flink|item|equipped_item|slot}}&lt;br /&gt;
{{Flink|int|expected_damage|{{opt|monster}}}}&lt;br /&gt;
{{Flink|float|experience_bonus}}&lt;br /&gt;
{{Flink|float|expression_eval}}&lt;br /&gt;
{{Flink|int [item]|extract_items|string}}&lt;br /&gt;
{{Flink|int|extract_meat|string}}&lt;br /&gt;
&lt;br /&gt;
===f===&lt;br /&gt;
{{Flink|item|familiar_equipment|familiar}}&lt;br /&gt;
{{Flink|item|familiar_equipped_equipment|familiar}}&lt;br /&gt;
{{Flink|int|familiar_weight|familiar}}&lt;br /&gt;
{{Flink|boolean|file_to_map|string|aggregate|{{opt|boolean}}}}&lt;br /&gt;
{{Flink|boolean|find|matcher}}&lt;br /&gt;
{{Flink|int|floor|float}}&lt;br /&gt;
{{Flink|string|form_field|string}}&lt;br /&gt;
{{Flink|string [string]|form_fields}}&lt;br /&gt;
{{Flink|string|format_date_time|string|string|string}}&lt;br /&gt;
{{Flink|boolean|friars_available}}&lt;br /&gt;
{{Flink|int|fullness_limit}}&lt;br /&gt;
&lt;br /&gt;
===g===&lt;br /&gt;
{{Flink|boolean|galaktik_cures_discounted}}&lt;br /&gt;
{{Flink|int|gameday_to_int}}&lt;br /&gt;
{{Flink|string|gameday_to_string}}&lt;br /&gt;
{{Flink|int|gametime_to_int}}&lt;br /&gt;
{{Flink|int|get_auto_attack}}&lt;br /&gt;
{{Flink|int [item]|get_campground}}&lt;br /&gt;
{{Flink|string|get_ccs_action|int}}&lt;br /&gt;
{{Flink|int|get_clan_id}}&lt;br /&gt;
{{Flink|string|get_clan_name}}&lt;br /&gt;
{{Flink|string|get_counters|string|int|int}}&lt;br /&gt;
{{Flink|string [int]|get_custom_outfits}}&lt;br /&gt;
{{Flink|item|get_dwelling|}}&lt;br /&gt;
{{Flink|string [int]|get_goals}}&lt;br /&gt;
{{Flink|int [item]|get_ingredients|item}}&lt;br /&gt;
{{Flink|int [item]|get_inventory}}&lt;br /&gt;
{{Flink|monster [int]|get_monsters|location}}&lt;br /&gt;
{{Flink|string [int]|get_moods}}&lt;br /&gt;
{{Flink|string [int]|get_outfits}}&lt;br /&gt;
{{Flink|string|get_path}}&lt;br /&gt;
{{Flink|string|get_path_full}}&lt;br /&gt;
{{Flink|string|get_path_variables}}&lt;br /&gt;
{{Flink|string|get_player_id|string}}&lt;br /&gt;
{{Flink|int|get_power|item}}&lt;br /&gt;
{{Flink|string|get_property|string}}&lt;br /&gt;
{{Flink|int [item]|get_related|item|string}}&lt;br /&gt;
{{Flink|int|get_revision}}&lt;br /&gt;
{{Flink|int [item]|get_shop}}&lt;br /&gt;
{{Flink|string|get_version}}&lt;br /&gt;
{{flink|boolean|gnomads_available}}&lt;br /&gt;
{{flink|boolean|goal_exists|string}}&lt;br /&gt;
{{Flink|string|group|matcher|{{opt|int}}}}&lt;br /&gt;
{{Flink|int|group_count|matcher}}&lt;br /&gt;
{{Flink|string [int, int]|group_string|string|string}}&lt;br /&gt;
{{Flink|item|guardians}}&lt;br /&gt;
{{Flink|boolean|guild_store_available}}&lt;br /&gt;
&lt;br /&gt;
===h===&lt;br /&gt;
{{Flink|boolean|have_bartender}}&lt;br /&gt;
{{Flink|boolean|have_chef}}&lt;br /&gt;
{{Flink|boolean|have_display}}&lt;br /&gt;
{{Flink|int|have_effect|effect}}&lt;br /&gt;
{{Flink|boolean|have_equipped|item}}&lt;br /&gt;
{{Flink|boolean|have_familiar|familiar}}&lt;br /&gt;
{{Flink|boolean|have_mushroom_plot}}&lt;br /&gt;
{{Flink|boolean|have_outfit|string}}&lt;br /&gt;
{{Flink|boolean|have_shop}}&lt;br /&gt;
{{Flink|boolean|have_skill|skill}}&lt;br /&gt;
{{Flink|boolean|hedgemaze}}&lt;br /&gt;
{{Flink|boolean|hermit|int|item}}&lt;br /&gt;
{{flink|boolean|hidden_temple_unlocked}}&lt;br /&gt;
{{Flink|boolean|hippy_stone_broken}}&lt;br /&gt;
{{Flink|boolean|hippy_store_available}}&lt;br /&gt;
{{Flink|float|historical_age|item}}&lt;br /&gt;
{{Flink|int|historical_price|item}}&lt;br /&gt;
&lt;br /&gt;
===i===&lt;br /&gt;
{{Flink|monster|image_to_monster|strict_string}}&lt;br /&gt;
{{Flink|boolean|in_bad_moon}}&lt;br /&gt;
{{Flink|boolean|in_hardcore}}&lt;br /&gt;
{{Flink|boolean|in_moxie_sign}}&lt;br /&gt;
{{Flink|boolean|in_muscle_sign}}&lt;br /&gt;
{{Flink|boolean|in_mysticality_sign}}&lt;br /&gt;
{{Flink|string|inaccessible_reason|coinmaster|}}&lt;br /&gt;
{{Flink|int|index_of|string|string|{{opt|int}}}}&lt;br /&gt;
{{Flink|int|inebriety_limit}}&lt;br /&gt;
{{Flink|float|initiative_modifier}}&lt;br /&gt;
{{Flink|buffer|insert|buffer|int|string}}&lt;br /&gt;
{{Flink|boolean|is_accessible|coinmaster}}&lt;br /&gt;
{{Flink|boolean|is_coinmaster_item|item}}&lt;br /&gt;
{{Flink|boolean|is_discardable|item}}&lt;br /&gt;
{{Flink|boolean|is_displayable|item}}&lt;br /&gt;
{{Flink|boolean|is_giftable|item}}&lt;br /&gt;
{{Flink|boolean|is_goal|item}}&lt;br /&gt;
{{Flink|boolean|is_integer|string}}&lt;br /&gt;
{{Flink|boolean|is_npc_item|item}}&lt;br /&gt;
{{Flink|boolean|is_online|string}}&lt;br /&gt;
{{Flink|boolean|is_tradeable|item}}&lt;br /&gt;
{{Flink|boolean|is_trendy|any}}&lt;br /&gt;
{{Flink|boolean|is_wearing_outfit|string}}&lt;br /&gt;
{{Flink|int|item_amount|item}}&lt;br /&gt;
{{Flink|float|item_drop_modifier}}&lt;br /&gt;
{{Flink|int [item]|item_drops|{{opt|monster}}}}&lt;br /&gt;
{{Flink|record [int]|item_drops_array|{{opt|monster}}}}&lt;br /&gt;
{{Flink|string|item_type|item}}&lt;br /&gt;
&lt;br /&gt;
===k===&lt;br /&gt;
{{flink|boolean|knoll_available}}&lt;br /&gt;
===l===&lt;br /&gt;
{{Flink|int|last_index_of|string|string|{{opt|int}}}}&lt;br /&gt;
{{Flink|string|last_item_message}}&lt;br /&gt;
{{Flink|monster|last_monster}}&lt;br /&gt;
{{Flink|string|last_skill_message}}&lt;br /&gt;
{{Flink|int|length|string}}&lt;br /&gt;
{{Flink|buffer|load_html|string}}&lt;br /&gt;
{{Flink|void|lock_familiar_equipment|boolean}}&lt;br /&gt;
{{Flink|void|logprint|string}}&lt;br /&gt;
===m===&lt;br /&gt;
{{Flink|string|make_url|string|boolean|boolean}}&lt;br /&gt;
{{Flink|int|mall_price|item}}&lt;br /&gt;
{{Flink|int|mana_cost_modifier}}&lt;br /&gt;
{{Flink|boolean|map_to_file|aggregate|string|{{opt|boolean}}}}&lt;br /&gt;
{{Flink|float|max|float|float}}&lt;br /&gt;
{{Flink|int|max|int|int}}&lt;br /&gt;
{{Flink|boolean|maximize|string|boolean}}&lt;br /&gt;
{{Flink|boolean|maximize|string|int|int|boolean}}&lt;br /&gt;
{{Flink|record [int]|maximize|string|int|int|boolean|boolean}}&lt;br /&gt;
{{Flink|int|meat_drop|{{opt|monster}}}}&lt;br /&gt;
{{Flink|float|meat_drop_modifier}}&lt;br /&gt;
{{Flink|float|min|float|float}}&lt;br /&gt;
{{Flink|int|min|int|int}}&lt;br /&gt;
{{Flink|item|minstrel_instrument}}&lt;br /&gt;
{{Flink|int|minstrel_level}}&lt;br /&gt;
{{Flink|boolean|minstrel_quest}}&lt;br /&gt;
{{Flink|int|mmg_bet_amount|int}}&lt;br /&gt;
{{Flink|string|mmg_bet_owner|int}}&lt;br /&gt;
{{Flink|int|mmg_bet_owner_id|int}}&lt;br /&gt;
{{Flink|string|mmg_bet_taker}}&lt;br /&gt;
{{Flink|string|mmg_bet_taker_id}}&lt;br /&gt;
{{Flink|int|mmg_bet_winnings}}&lt;br /&gt;
{{Flink|int|mmg_make_bet|int|boolean}}&lt;br /&gt;
{{Flink|int [int]|mmg_my_bets}}&lt;br /&gt;
{{Flink|int [int]|mmg_offered_bets}}&lt;br /&gt;
{{Flink|boolean|mmg_retract_bet|int}}&lt;br /&gt;
{{Flink|void|mmg_search|int|int}}&lt;br /&gt;
{{Flink|int|mmg_take_bet|int|boolean}}&lt;br /&gt;
{{Flink|void|mmg_visit}}&lt;br /&gt;
{{Flink|int|mmg_wait_event|int}}&lt;br /&gt;
{{Flink|float|modifier_eval|string}}&lt;br /&gt;
{{Flink|int|monster_attack|{{opt|monster}}}}&lt;br /&gt;
{{Flink|int|monster_defense|{{opt|monster}}}}&lt;br /&gt;
{{Flink|element|monster_element|{{opt|monster}}}}&lt;br /&gt;
{{Flink|float|monster_eval|string}}&lt;br /&gt;
{{Flink|int|monster_hp|{{opt|monster}}}}&lt;br /&gt;
{{Flink|int|monster_level_adjustment}}&lt;br /&gt;
{{Flink|phylum|monster_phylum|{{opt|monster}}}}&lt;br /&gt;
{{Flink|int|moon_light}}&lt;br /&gt;
{{Flink|int|moon_phase}}&lt;br /&gt;
{{Flink|int|mp_cost|skill}}&lt;br /&gt;
{{Flink|int|my_adventures}}&lt;br /&gt;
{{Flink|int|my_ascensions}}&lt;br /&gt;
{{Flink|int|my_basestat|stat}}&lt;br /&gt;
{{Flink|int|my_buffedstat|stat}}&lt;br /&gt;
{{Flink|class|my_class}}&lt;br /&gt;
{{Flink|int|my_closet_meat}}&lt;br /&gt;
{{Flink|string|my_companion}}&lt;br /&gt;
{{Flink|int|my_daycount|}}&lt;br /&gt;
{{Flink|familiar|my_effective_familiar}}&lt;br /&gt;
{{Flink|int [effect]|my_effects}}&lt;br /&gt;
{{Flink|familiar|my_enthroned_familiar}}&lt;br /&gt;
{{Flink|familiar|my_familiar}}&lt;br /&gt;
{{Flink|int|my_fullness}}&lt;br /&gt;
{{Flink|string|my_hash}}&lt;br /&gt;
{{Flink|int|my_hp}}&lt;br /&gt;
{{Flink|string|my_id}}&lt;br /&gt;
{{Flink|int|my_inebriety}}&lt;br /&gt;
{{Flink|int|my_level}}&lt;br /&gt;
{{Flink|location|my_location}}&lt;br /&gt;
{{Flink|int|my_maxhp}}&lt;br /&gt;
{{Flink|int|my_maxmp}}&lt;br /&gt;
{{Flink|int|my_meat}}&lt;br /&gt;
{{Flink|int|my_mp}}&lt;br /&gt;
{{Flink|string|my_name}}&lt;br /&gt;
{{flink|string|my_path}}&lt;br /&gt;
{{Flink|stat|my_primestat}}&lt;br /&gt;
{{flink|string|my_sign}}&lt;br /&gt;
{{Flink|int|my_spleen_use}}&lt;br /&gt;
{{Flink|int|my_turncount}}&lt;br /&gt;
&lt;br /&gt;
===n===&lt;br /&gt;
{{Flink|float|now_to_string|string}}&lt;br /&gt;
{{Flink|int|npc_price|item}}&lt;br /&gt;
{{Flink|float|numeric_modifier|string|{{opt|string}}}}&lt;br /&gt;
{{Flink|float|numeric_modifier|item|string}}&lt;br /&gt;
{{Flink|float|numeric_modifier|effect|string}}&lt;br /&gt;
{{Flink|float|numeric_modifier|skill|string}}&lt;br /&gt;
{{Flink|float|numeric_modifier|familiar|string|int|item}}&lt;br /&gt;
&lt;br /&gt;
===o===&lt;br /&gt;
{{Flink|boolean|outfit|string}}&lt;br /&gt;
{{Flink|item [int]|outfit_pieces|string}}&lt;br /&gt;
{{Flink|boolean|overdrink|int|item}}&lt;br /&gt;
&lt;br /&gt;
===p===&lt;br /&gt;
{{Flink|void|print|string|{{opt|string}}}}&lt;br /&gt;
{{Flink|void|print_html|string}}&lt;br /&gt;
{{Flink|int|pulls_remaining}}&lt;br /&gt;
{{Flink|boolean|put_closet|int|{{opt|item}}}}&lt;br /&gt;
{{Flink|boolean|put_display|int|item}}&lt;br /&gt;
{{Flink|boolean|put_shop|int|int|{{opt|int}}|item}}&lt;br /&gt;
{{Flink|boolean|put_stash|int|item}}&lt;br /&gt;
{{Flink|int|pvp_attacks_left}}&lt;br /&gt;
===r===&lt;br /&gt;
{{Flink|int|random|int}}&lt;br /&gt;
{{Flink|int|raw_damage_absorption}}&lt;br /&gt;
{{Flink|boolean|refresh_stash}}&lt;br /&gt;
{{Flink|boolean|refresh_status}}&lt;br /&gt;
{{Flink|void|remove_item_condition|int|item}}&lt;br /&gt;
{{Flink|boolean|replace|buffer|int|int|string}}&lt;br /&gt;
{{Flink|string|replace_all|matcher|string}}&lt;br /&gt;
{{Flink|string|replace_first|matcher|string}}&lt;br /&gt;
{{Flink|buffer|replace_string|buffer|string|string}}&lt;br /&gt;
{{Flink|buffer|replace_string|string|string|string}}&lt;br /&gt;
{{Flink|matcher|reset|matcher|{{opt|string}}}}&lt;br /&gt;
{{Flink|boolean|restore_hp|int}}&lt;br /&gt;
{{Flink|boolean|restore_mp|int}}&lt;br /&gt;
{{Flink|boolean|retrieve_item|int|item}}&lt;br /&gt;
{{Flink|int|round|float}}&lt;br /&gt;
{{Flink|buffer|run_combat}}&lt;br /&gt;
{{Flink|buffer|runaway}}&lt;br /&gt;
&lt;br /&gt;
===s===&lt;br /&gt;
{{Flink|boolean|sell|coinmaster|int|item}}&lt;br /&gt;
{{Flink|int|sell_price|coinmaster|item}}&lt;br /&gt;
{{Flink|boolean|sells_item|coinmaster|item}}&lt;br /&gt;
{{Flink|string [int]|session_logs|{{opt|string}}|int}}&lt;br /&gt;
{{Flink|void|set_auto_attack|int}}&lt;br /&gt;
{{Flink|void|set_length|buffer|int}}&lt;br /&gt;
{{Flink|void|set_location|location}}&lt;br /&gt;
{{Flink|void|set_property|string|string}}&lt;br /&gt;
{{Flink|int|shop_amount|item}}&lt;br /&gt;
{{Flink|int|spleen_limit}}&lt;br /&gt;
{{Flink|string [int]|split_string|string|{{opt|string}}}}&lt;br /&gt;
{{Flink|float|square_root|float}}&lt;br /&gt;
{{Flink|int|start|matcher|{{opt|int}}}}&lt;br /&gt;
{{Flink|int|stash_amount|item}}&lt;br /&gt;
{{Flink|stat|stat_bonus_today}}&lt;br /&gt;
{{Flink|stat|stat_bonus_tomorrow}}&lt;br /&gt;
{{Flink|stat|stat_modifier|effect|string}}&lt;br /&gt;
{{Flink|buffer|steal}}&lt;br /&gt;
{{Flink|int|stills_available}}&lt;br /&gt;
{{Flink|int|storage_amount|item}}&lt;br /&gt;
{{Flink|string|string_modifier|string}}&lt;br /&gt;
{{Flink|string|string_modifier|string|string}}&lt;br /&gt;
{{Flink|string|substring|string|int|{{opt|int}}}}&lt;br /&gt;
&lt;br /&gt;
===t===&lt;br /&gt;
{{Flink|boolean|take_closet|int|{{opt|item}}}}&lt;br /&gt;
{{Flink|boolean|take_display|int|item}}&lt;br /&gt;
{{Flink|boolean|take_shop|item|{{opt|boolean}}}}&lt;br /&gt;
{{Flink|boolean|take_stash|int|item}}&lt;br /&gt;
{{Flink|boolean|take_storage|int|item}}&lt;br /&gt;
{{Flink|int|tavern|{{opt|string}}}}&lt;br /&gt;
{{Flink|buffer|throw_item|item}}&lt;br /&gt;
{{Flink|buffer|throw_items|item|item}}&lt;br /&gt;
{{Flink|buffer|time_to_string}}&lt;br /&gt;
{{Flink|boolean|to_boolean|any}}&lt;br /&gt;
{{Flink|class|to_class|string}}&lt;br /&gt;
{{Flink|coinmaster|to_coinmaster|string}}&lt;br /&gt;
{{Flink|effect|to_effect|int}}&lt;br /&gt;
{{Flink|effect|to_effect|string}}&lt;br /&gt;
{{Flink|effect|to_effect|skill}}&lt;br /&gt;
{{Flink|element|to_element|string}}&lt;br /&gt;
{{Flink|familiar|to_familiar|int}}&lt;br /&gt;
{{Flink|familiar|to_familiar|string}}&lt;br /&gt;
{{Flink|float|to_float|any}}&lt;br /&gt;
{{Flink|int|to_int|any}}&lt;br /&gt;
{{Flink|item|to_item|string}}&lt;br /&gt;
{{Flink|item|to_item|int}}&lt;br /&gt;
{{Flink|item|to_item|string|int}}&lt;br /&gt;
{{Flink|string|to_json|null}}&lt;br /&gt;
{{Flink|location|to_location|string}}&lt;br /&gt;
{{Flink|location|to_location|int}}&lt;br /&gt;
{{Flink|string|to_lower_case|string}}&lt;br /&gt;
{{Flink|monster|to_monster|string}}&lt;br /&gt;
{{Flink|phylum|to_phylum|string}}&lt;br /&gt;
{{Flink|string|to_plural|item}}&lt;br /&gt;
{{Flink|skill|to_skill|int}}&lt;br /&gt;
{{Flink|skill|to_skill|string}}&lt;br /&gt;
{{Flink|skill|to_skill|effect}}&lt;br /&gt;
{{Flink|slot|to_slot|item}}&lt;br /&gt;
{{Flink|stat|to_stat|string}}&lt;br /&gt;
{{Flink|string|to_string|any}}&lt;br /&gt;
{{Flink|string|to_upper_case|string}}&lt;br /&gt;
{{Flink|string|to_url|location}}&lt;br /&gt;
{{Flink|string|today_to_string}}&lt;br /&gt;
{{Flink|int|truncate|float}}&lt;br /&gt;
{{Flink|int|turns_per_cast|skill}}&lt;br /&gt;
{{Flink|int|turns_played}}&lt;br /&gt;
&lt;br /&gt;
===u===&lt;br /&gt;
{{Flink|string|url_decode|string}}&lt;br /&gt;
{{Flink|string|url_encode|string}}&lt;br /&gt;
{{Flink|boolean|use|int|item}}&lt;br /&gt;
{{Flink|boolean|use_familiar|familiar}}&lt;br /&gt;
{{Flink|boolean|use_skill|int|skill|{{opt|string}}}}&lt;br /&gt;
{{Flink|buffer|use_skill|skill}}&lt;br /&gt;
{{Flink|boolean|user_confirm|string}}&lt;br /&gt;
{{Flink|boolean|user_confirm|string|int|boolean}}&lt;br /&gt;
&lt;br /&gt;
===v===&lt;br /&gt;
{{Flink|boolean|visit|coinmaster}}&lt;br /&gt;
{{Flink|buffer|visit_url|string}}&lt;br /&gt;
{{Flink|buffer|visit_url|string|boolean}}&lt;br /&gt;
{{Flink|buffer|visit_url|string|boolean|boolean}}&lt;br /&gt;
===w===&lt;br /&gt;
{{Flink|void|wait|int}}&lt;br /&gt;
{{Flink|void|waitq|int}}&lt;br /&gt;
{{Flink|int|weapon_hands|item}}&lt;br /&gt;
{{Flink|stat|weapon_type|item}}&lt;br /&gt;
{{Flink|int|weight_adjustment}}&lt;br /&gt;
{{Flink|boolean|white_citadel_available}}&lt;br /&gt;
{{Flink|boolean [string]|who_clan}}&lt;br /&gt;
{{Flink|boolean|will_usually_dodge}}&lt;br /&gt;
{{Flink|boolean|will_usually_miss}}&lt;br /&gt;
{{Flink|void|write|string}}&lt;br /&gt;
{{Flink|void|writeln|string}}&lt;/div&gt;</summary>
		<author><name>PsyMar</name></author>
	</entry>
	<entry>
		<id>https://wiki.kolmafia.us/index.php?title=Data_Structures&amp;diff=3203</id>
		<title>Data Structures</title>
		<link rel="alternate" type="text/html" href="https://wiki.kolmafia.us/index.php?title=Data_Structures&amp;diff=3203"/>
		<updated>2013-06-30T21:16:59Z</updated>

		<summary type="html">&lt;p&gt;PsyMar: /* Assignments */ fix comments to reflect code&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{TOCright}}&lt;br /&gt;
&lt;br /&gt;
KoLmafia supports complex data structures such as maps and records made from simple [[Data Types|data types]].&lt;br /&gt;
&lt;br /&gt;
== Maps ==&lt;br /&gt;
Most of this information was copied directly from ASH Maps Tutorial, by Veracity (http://kolmafia.sourceforge.net/advanced.html#maps)&lt;br /&gt;
&lt;br /&gt;
A map is indexed by one data type (the key) and associates that key with another (or the same) data type (the value). The key can be any ASH simple data type: boolean, int, float, string, item, location, class, stat, skill, effect, familiar, slot, or monster. The value can be any ASH data type at all: a simple type, a record, or can be another map. This effectively allows multi-dimensional maps and. In fact, that&#039;s how the syntax we provide for multi-dimensional maps actually operate: maps of maps of maps ...&lt;br /&gt;
&lt;br /&gt;
You can declare a map any time you can declare a variable: as a top level (global) variable, as a function parameter, or as a local variable in any scope.&lt;br /&gt;
&lt;br /&gt;
You can fetch data from a map any time you can provide a data value: in an expression, as a function parameter, on the right side of an assignment statement, from a &amp;quot;return&amp;quot; statement, as so on. You can pass around entire maps, individual elements, or intermediate maps: &amp;quot;slices&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Declarations ===&lt;br /&gt;
&lt;br /&gt;
The syntax for declaring the data type of a map:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;data type&amp;gt; [ &amp;lt;key type&amp;gt;, ... ] &amp;lt;aggregate_name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
{{CodeSample&lt;br /&gt;
|code=&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
string [item] map1;&lt;br /&gt;
float [class, string, int] another_map;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Assignments ===&lt;br /&gt;
&lt;br /&gt;
If you use a map on the left side of an assignment, you set the whole map at once to the new value.&lt;br /&gt;
&lt;br /&gt;
{{CodeSample&lt;br /&gt;
|code=&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
int [item] my_pricelist;&lt;br /&gt;
int [item] new_pricelist;&lt;br /&gt;
&lt;br /&gt;
/* Some code that updates my_pricelist with new_pricelist */&lt;br /&gt;
&lt;br /&gt;
my_pricelist = new_pricelist;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
If you specify a map and a complete set of indices (of the correct types) on the left side of an assignment statement, you set a single element.&lt;br /&gt;
&lt;br /&gt;
{{CodeSample&lt;br /&gt;
|code=&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
int [item] my_pricelist;&lt;br /&gt;
my_pricelist[ $item[ pail ] ] = 1000;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
If you specify a map and a prefix of indices (of the correct type), you directly set one of the intermediate maps, a &amp;quot;slice&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
{{CodeSample&lt;br /&gt;
|code=&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
float [string, int, string] my_map;&lt;br /&gt;
float [int, string] slice1;&lt;br /&gt;
&lt;br /&gt;
/* Some code that fills my_map[ &amp;quot;slice1&amp;quot; ] with slice1 */&lt;br /&gt;
my_map[ &amp;quot;slice1&amp;quot; ] = slice1;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== References ===&lt;br /&gt;
&lt;br /&gt;
The syntax for referencing an element (or slice) of a map:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;aggregate name&amp;gt;[ &amp;lt;key expression&amp;gt;, ... ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All the key expressions will be evaluated at run time. If you specify all the keys the map expects, you fetch data of the type specified by the map. If you specify fewer keys than the map expects, you get an intermediate map, a &amp;quot;slice&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
As an example:&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
boolean [string, string] props; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
might be used to hold &amp;quot;properties&amp;quot; associated with names.&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
props[ &amp;quot;dog&amp;quot;, &amp;quot;mammal&amp;quot; ] = true; &lt;br /&gt;
props[ &amp;quot;dog&amp;quot;, &amp;quot;pet&amp;quot; ] = true; &lt;br /&gt;
props[ &amp;quot;dog&amp;quot;, &amp;quot;fun&amp;quot; ] = false;&lt;br /&gt;
props[ &amp;quot;turtle&amp;quot;, &amp;quot;mammal&amp;quot; ] = false;&lt;br /&gt;
props[ &amp;quot;turtle&amp;quot;, &amp;quot;pet&amp;quot; ] = true;&lt;br /&gt;
props[ &amp;quot;turtle&amp;quot;, &amp;quot;fun&amp;quot; ] = false;&lt;br /&gt;
props[ &amp;quot;aardvark&amp;quot;, &amp;quot;mammal&amp;quot; ] = true;&lt;br /&gt;
props[ &amp;quot;aardvark&amp;quot;, &amp;quot;pet&amp;quot; ] = false;&lt;br /&gt;
props[ &amp;quot;aardvark&amp;quot;, &amp;quot;fun&amp;quot; ] = true; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
references:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
props[ &amp;quot;dog&amp;quot;, &amp;quot;mammal&amp;quot;] =&amp;gt; true&lt;br /&gt;
boolean [string] animal = props[ &amp;quot;turtle&amp;quot; ];&lt;br /&gt;
animal[ &amp;quot;fun&amp;quot; ] =&amp;gt; false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Contains ===&lt;br /&gt;
&lt;br /&gt;
You can test the presence of a key in a map using the &amp;quot;contains&amp;quot; operator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;aggregate reference expression&amp;gt; contains &amp;lt;key expression&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;aggregate reference expression&amp;gt; must evaluate at run time to a map or slice, and must evaluate at run time to a key of the appropriate type. (Note that that is enforced at parse time; ASH can tell the datatype any expression will produce).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
props contains &amp;quot;dog&amp;quot; =&amp;gt; true&lt;br /&gt;
props contains &amp;quot;elephant&amp;quot; =&amp;gt; false&lt;br /&gt;
props[ &amp;quot;aardvark&amp;quot; ] contains &amp;quot;fun&amp;quot; =&amp;gt; true&lt;br /&gt;
animal contains &amp;quot;pet&amp;quot; =&amp;gt; true&lt;br /&gt;
animal contains &amp;quot;favorite food&amp;quot; =&amp;gt; false&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Remove ===&lt;br /&gt;
&lt;br /&gt;
You can remove a key-value association from a map using the &amp;quot;remove&amp;quot; unary operator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
remove &amp;lt;aggregate reference&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For clarification, an aggregate reference is &amp;quot;&amp;lt;map name&amp;gt;[ &amp;lt;index 1&amp;gt; ... &amp;lt;index n&amp;gt; ]&amp;quot; where &amp;lt;map name&amp;gt;[ &amp;lt;index 1&amp;gt; ... &amp;lt;index n-1&amp;gt; ] specifies the &amp;quot;slice&amp;quot; and &amp;lt;index n&amp;gt; specifies the &amp;quot;key&amp;quot;. Which is just what you expect, if you fully specify the indices; for a single dimensional map, &amp;quot;map[10]&amp;quot; -&amp;gt; &amp;quot;map&amp;quot; is the slice and 10 is the key. The &amp;quot;remove&amp;quot; operator removes the &amp;quot;key&amp;quot; from the &amp;quot;slice&amp;quot;. For example:&lt;br /&gt;
&lt;br /&gt;
{{CodeSample|code=&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
string [int] map1;&lt;br /&gt;
map1[5] = &amp;quot;foo&amp;quot;;&lt;br /&gt;
print( count( map1 ) + &amp;quot; &amp;quot; + map1 contains 5 + &amp;quot; &amp;quot; + map1[5] );&lt;br /&gt;
print( &amp;quot;remove: &amp;quot; + remove map1[5] );&lt;br /&gt;
print( count( map1 ) + &amp;quot; &amp;quot; + map1 contains 5 + &amp;quot; &amp;quot;  + map1[5] );&lt;br /&gt;
print( &amp;quot;remove: &amp;quot; + remove map1[5] );&lt;br /&gt;
int [string, string] map2;&lt;br /&gt;
map2[&amp;quot;me&amp;quot;,&amp;quot;you&amp;quot;] = 17;&lt;br /&gt;
print( count( map2[&amp;quot;me&amp;quot;] ) + &amp;quot; &amp;quot; + map2[&amp;quot;me&amp;quot;] contains &amp;quot;you&amp;quot; + &amp;quot; &amp;quot; + map2[&amp;quot;me&amp;quot;,&amp;quot;you&amp;quot;] );&lt;br /&gt;
print( &amp;quot;remove: &amp;quot; + remove map2[&amp;quot;me&amp;quot;, &amp;quot;you&amp;quot;] );&lt;br /&gt;
print( count( map2[&amp;quot;me&amp;quot;] ) + &amp;quot; &amp;quot; + map2[&amp;quot;me&amp;quot;] contains &amp;quot;you&amp;quot; + &amp;quot; &amp;quot; + map2[&amp;quot;me&amp;quot;,&amp;quot;you&amp;quot;] );&lt;br /&gt;
print( &amp;quot;remove: &amp;quot; + remove map2[&amp;quot;me&amp;quot;, &amp;quot;you&amp;quot;] );&lt;br /&gt;
print( count( map2 ) + &amp;quot; &amp;quot; + map2[&amp;quot;me&amp;quot;] );&lt;br /&gt;
print( &amp;quot;remove: &amp;quot; + remove map2[&amp;quot;me&amp;quot;] );&lt;br /&gt;
print( count( map2 ) + &amp;quot; &amp;quot; + map2[&amp;quot;me&amp;quot;] );&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
yields:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1 true foo&lt;br /&gt;
remove: foo&lt;br /&gt;
0 false&lt;br /&gt;
remove:&lt;br /&gt;
1 true 17&lt;br /&gt;
remove: 17&lt;br /&gt;
0 false 0&lt;br /&gt;
remove: 0&lt;br /&gt;
1 aggregate int [string]&lt;br /&gt;
remove: aggregate int [string]&lt;br /&gt;
0 aggregate int [string]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Clear ===&lt;br /&gt;
&lt;br /&gt;
You can remove all &amp;lt;code&amp;gt;key =&amp;gt; value&amp;lt;/code&amp;gt; entries from a map using the {{f|clear}} function:&lt;br /&gt;
&lt;br /&gt;
{{CodeSample|code=&amp;lt;syntaxhighlight&amp;gt;clear( &amp;lt;aggregate&amp;gt; );&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Count ===&lt;br /&gt;
&lt;br /&gt;
The {{f|count}} function returns the number of defined keys for the specified aggregate.&lt;br /&gt;
&lt;br /&gt;
{{CodeSample|code=&amp;lt;syntaxhighlight&amp;gt;int size = count( &amp;lt;aggregate&amp;gt; );&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Sort ===&lt;br /&gt;
&lt;br /&gt;
From http://kolmafia.us/showthread.php?t=1738 and http://kolmafia.us/showthread.php?10729&lt;br /&gt;
&lt;br /&gt;
The syntax is:&lt;br /&gt;
{{CodeSample|code=&amp;lt;syntaxhighlight&amp;gt;sort aggregate by keyExpr;&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;aggregate&amp;lt;/code&amp;gt; is a reference to the object to be sorted - arrays are probably the most useful things to sort, but any mapping type can be used.  But please note that when you sort a map, you change the values that correspond to the index. To sort on a map, you would want to use a multidimensional maps, but note that you can only sort along a single dimension at a time when doing this. Simply put... &amp;quot;sort&amp;quot; is only useful in cases where your data exists entirely in the values of the map; the keys can have no meaning beyond simply being distinct.&lt;br /&gt;
&lt;br /&gt;
The reference must not be enclosed in parentheses, as that would look like a call to a function named &amp;lt;code&amp;gt;sort()&amp;lt;/code&amp;gt; - which is still perfectly valid, &amp;quot;sort&amp;quot; has not become a [[Reserved Words|reserved word]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;keyExpr&amp;lt;/code&amp;gt; is an arbitrary expression that defines how the items should be ordered. It is evaluated once for every entry in the aggregate, in a scope with two additional variables implicitly defined: &#039;&amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt;&#039; and &#039;&amp;lt;code&amp;gt;value&amp;lt;/code&amp;gt;&#039;, holding the details of that entry. The value of the &amp;lt;code&amp;gt;keyExpr&amp;lt;/code&amp;gt; is used as the sort key; typically it would be an &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;string&amp;lt;/code&amp;gt;, but can be any ASH type that can be compared via &amp;quot;&amp;lt;&amp;quot; and the other relational operators.&lt;br /&gt;
&lt;br /&gt;
The most basic form of sorting would therefore be &amp;quot;&amp;lt;code&amp;gt;sort ... by value&amp;lt;/code&amp;gt;&amp;quot;, but many useful things can be done with the use of a more complex &amp;lt;code&amp;gt;keyExpr&amp;lt;/code&amp;gt; - the only real restriction is that the expression should not modify the object you&#039;re sorting. For example, if you had an array of items, you could sort it &amp;quot;&amp;lt;code&amp;gt;by autosell_price(value)&amp;lt;/code&amp;gt;&amp;quot;. An array of weapon items could be sorted &amp;quot;&amp;lt;code&amp;gt;by -get_power(value)&amp;lt;/code&amp;gt;&amp;quot; to put it in decreasing order of power. If the elements of your aggregate are records, you&#039;d need to use something like &amp;quot;&amp;lt;code&amp;gt;by value.fieldName&amp;lt;/code&amp;gt;&amp;quot;, since the records themselves can&#039;t be meaningfully compared.&lt;br /&gt;
&lt;br /&gt;
After the sort statement, the aggregate will have exactly the same sets of keys and values as before (even if the keys weren&#039;t consecutive), and the iteration order of the keys will be the same, but the values will likely be associated with different keys. The sort is stable - in other words, elements with sort keys that compare as equal will remain in the same order. This means that you can sort on multiple criteria by simply performing separate sorts for each of the criteria, in increasing order of significance.&lt;br /&gt;
&lt;br /&gt;
To find out how many things you have, you might do:&lt;br /&gt;
{{CodeSample|code=&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
item [int] whatGot;&lt;br /&gt;
int ctr =0;&lt;br /&gt;
&lt;br /&gt;
foreach it in get_inventory() {&lt;br /&gt;
   whatGot[ctr] = it;&lt;br /&gt;
   ctr+=1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
sort whatGot by item_amount(value);&lt;br /&gt;
&lt;br /&gt;
foreach x, it in whatGot&lt;br /&gt;
   print(item_amount(it) + &#039; of &#039; + it);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
Note that this use of an optional feature of foreach. The second variable in the foreach is the value of whatGot[x].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A few more examples of things you can do:&lt;br /&gt;
* &amp;quot;&amp;lt;code&amp;gt;by -value&amp;lt;/code&amp;gt;&amp;quot; sorts integers in decreasing order (there&#039;s no similar trick for &amp;lt;code&amp;gt;string&amp;lt;/code&amp;gt; values).&lt;br /&gt;
* &amp;quot;&amp;lt;code&amp;gt;by -index&amp;lt;/code&amp;gt;&amp;quot; reverses the existing order of an array (or map with integer keys).&lt;br /&gt;
* &amp;quot;&amp;lt;code&amp;gt;by random(1000000)&amp;lt;/code&amp;gt;&amp;quot; shuffles into a random order.&lt;br /&gt;
* &amp;quot;&amp;lt;code&amp;gt;by otherArray[index]&amp;lt;/code&amp;gt;&amp;quot; uses values from a parallel array as the sort keys (you&#039;d then need to do &amp;quot;&amp;lt;code&amp;gt;sort otherArray by value;&amp;lt;/code&amp;gt;&amp;quot; if you wanted the two arrays to remain in sync).&lt;br /&gt;
&lt;br /&gt;
===Iteration===&lt;br /&gt;
To iterate through a map, use the &#039;&#039;&#039;foreach&#039;&#039;&#039; operator. For instance, if you wanted to print out how many of each item you had, you could do something like the following:&lt;br /&gt;
{{CodeSample|code=&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
int[item] map = get_inventory();&lt;br /&gt;
foreach key in map {&lt;br /&gt;
    print(key + &amp;quot; (&amp;quot; + map[key] + &amp;quot;)&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Multidimensional maps are implemented as maps that map keys to maps. &#039;&#039;&#039;int[item][string]map&#039;&#039;&#039; is really a mapping of items to int[string] maps. Iteration, therefore, is as follows:&lt;br /&gt;
{{CodeSample|code=&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
int[item][string] map;&lt;br /&gt;
file_to_map(&amp;quot;somefile.txt&amp;quot;, map);&lt;br /&gt;
foreach k1 in map {&lt;br /&gt;
    print(k1 + &amp;quot;: &amp;quot;);&lt;br /&gt;
    foreach k2 in map[k1] {&lt;br /&gt;
        print(&amp;quot;\t&amp;quot; + k2 + &amp;quot;: &amp;quot; + map[k1][k2]);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Two things to note: First, &#039;&#039;&#039;int[item][string]map&#039;&#039;&#039; is equivalent to &#039;&#039;&#039;int[item, string]map&#039;&#039;&#039;. This really comes down to author preference, although the second form is generally more common. Second, the two following foreach loops are equivalent:&lt;br /&gt;
{{CodeSample|code=&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
int[item][string] map;&lt;br /&gt;
foreach k1 in map {&lt;br /&gt;
    foreach k2 in map[k1] {&lt;br /&gt;
        func(map[k1][k2]);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
foreach k1, k2 in map {&lt;br /&gt;
    func(map[k1][k2]);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Of course, the latter does not lend itself to, say, only printing the first key once, whereas the former can be used that way (see the preceding example).&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
Maps in ASH are implemented internally as TreeMaps [http://download.oracle.com/javase/1.5.0/docs/api/java/util/TreeMap.html]. See below for some implications.&lt;br /&gt;
&lt;br /&gt;
== Arrays ==&lt;br /&gt;
These look and behave like mappings of integers to values, where the keys only take values from 0 to n, but these are implemented as Java Arrays.&lt;br /&gt;
&lt;br /&gt;
===Differences between arrays and maps===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;item [12] array;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Can use keys 0 - 11. You get a runtime error if you use any other key. It always uses memory to hold 12 items, even if you only use a couple of them. But it&#039;s a constant time - O(1) - to access any element.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;item [int] map;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Can use any int as a key. It has constant memory for the Java map, and additional memory for each element in the map, but is O( log n) to access any particular element.&lt;br /&gt;
&lt;br /&gt;
If you are able to use (a fairly densely packed set of) integers as keys, your program will be faster and use (potentially) slightly more memory.&lt;br /&gt;
&lt;br /&gt;
If you have a sparse set of integers, you can still use an array and get fast access, but you will waste a lot of memory.&lt;br /&gt;
&lt;br /&gt;
If you can&#039;t use integers as keys or don&#039;t want to waste memory on a sparse array, you can have a slower but less memory consuming map.&lt;br /&gt;
&lt;br /&gt;
[http://kolmafia.us/showthread.php?6425-Sorting-skills-by-mana-cost&amp;amp;p=48703&amp;amp;viewfull=1#post48703]&lt;br /&gt;
&lt;br /&gt;
====Time considerations====&lt;br /&gt;
* Given &#039;&#039;&#039;if (a == item1 || a == item2 || a == item3)&#039;&#039;&#039; and &#039;&#039;&#039;if ($items[item1, item2, item3] contains a)&#039;&#039;&#039;, which is faster?&lt;br /&gt;
&lt;br /&gt;
This is going to depend on the number of items in the list, and which one happens to match; if &#039;a&#039; is almost always item1, then the first form is likely to win on practical grounds, even though it&#039;s theoretically slower (O(n) vs. O(log n)).&lt;br /&gt;
&lt;br /&gt;
The second form is a definite win assuming no such coincidences of the item chosen, a somewhat larger set of items, and that the code is executed more than once per run of the script. The first lookup in a plural constant actually builds an internal map that allows such queries to be efficiently done; this is deferred because typical use of a plural constant involves only iteration, not lookups.&lt;br /&gt;
&lt;br /&gt;
There&#039;s always the &amp;quot;profile&amp;quot; command, if you really need to know which is more efficient in a given situation - although it&#039;s unlikely that either would have a noticeable effect on your script&#039;s performance.&lt;br /&gt;
&lt;br /&gt;
[http://kolmafia.us/showthread.php?6425-Sorting-skills-by-mana-cost&amp;amp;p=48728&amp;amp;viewfull=1#post48728]&lt;br /&gt;
&lt;br /&gt;
== Records ==&lt;br /&gt;
&lt;br /&gt;
(copy-pasted from Veracity&#039;s post introducing the record [http://kolmafia.us/showthread.php?t=280])&lt;br /&gt;
&lt;br /&gt;
Starting with SVN revision 1311 of KoLmafia, ASH now supports a new kind of structured data: the record. Here is a little example of how you declare a record and variables of the new type you&#039;ve created by doing so.&lt;br /&gt;
&lt;br /&gt;
{{CodeSample|code=&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
record my_type {&lt;br /&gt;
  	int ifield;&lt;br /&gt;
	string sfield;&lt;br /&gt;
	record {&lt;br /&gt;
		int first;&lt;br /&gt;
		int second;&lt;br /&gt;
	} rfield;&lt;br /&gt;
	int [int, int] mfield;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
my_type rvar;&lt;br /&gt;
my_type [int] mrvar;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
What I&#039;ve done with the above is declare a new data type which I&#039;ve named &amp;quot;my_type&amp;quot;. Having declared the new type, I can use it (almost) anywhere that I can use a built-in type name. I declared a variable, &amp;quot;rvar&amp;quot;, of that type, and I defined a map, &amp;quot;mrvar&amp;quot;, which maps keys of type integer to values of type my_type.&lt;br /&gt;
&lt;br /&gt;
The new type, &amp;quot;my_type&amp;quot; is a &amp;quot;composite&amp;quot; type. It contains four fields. &amp;quot;ifield&amp;quot; is an integer. &amp;quot;sfield&amp;quot; is a string. &amp;quot;rfield&amp;quot; is another composite field: an anonymous record containing two integers named &amp;quot;first&amp;quot; and &amp;quot;second&amp;quot;. Finally, &amp;quot;mfield&amp;quot; is a map from [int, int] to int.&lt;br /&gt;
&lt;br /&gt;
As you can see, a record can combine data of all the types ASH supports: primitive, aggregate, and composite.&lt;br /&gt;
&lt;br /&gt;
Having defined the new data type and several variables using it, here are some examples of how to access the fields.&lt;br /&gt;
&lt;br /&gt;
{{CodeSample|code=&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
rvar.ifield = 10;&lt;br /&gt;
rvar.sfield = &amp;quot;secret&amp;quot;;&lt;br /&gt;
rvar.rfield.first = 1000;&lt;br /&gt;
rvar.rfield.second = 2000;&lt;br /&gt;
rvar.mfield[ 2, 3 ] = 12;&lt;br /&gt;
&lt;br /&gt;
mrvar[ 1 ] = rvar;&lt;br /&gt;
&lt;br /&gt;
foreach key in mrvar&lt;br /&gt;
	foreach key1, key2 in mrvar[key].mfield&lt;br /&gt;
		print( &amp;quot;val = &amp;quot; + mrvar[key].mfield[key1,key2] );&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As you can see, if you have a variable that is a record, you access the fields of the record by following the variable name with &amp;quot;.&amp;amp;lt;field name&amp;amp;gt;&amp;quot;. The resulting value will be of whatever type you declared in the definition of the record. If the value is a map, you can give a list of keys within [], just like any other map. If the value is another record, you can access the fields of the nested record by using another &amp;quot;.&amp;amp;lt;field name&amp;amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
If you are familiar with Pascal &amp;quot;records&amp;quot; or C/C++ &amp;quot;structs&amp;quot;, this should all be comfortably familiar.&lt;br /&gt;
&lt;br /&gt;
Finally, if you create a map whose values is a record, the file_to_map and map_to_file built-in ASH functions will Do The Right Thing; they will efficiently and reliably save and restore your data.&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting]]&lt;/div&gt;</summary>
		<author><name>PsyMar</name></author>
	</entry>
	<entry>
		<id>https://wiki.kolmafia.us/index.php?title=Custom_Combat_Script&amp;diff=4438</id>
		<title>Custom Combat Script</title>
		<link rel="alternate" type="text/html" href="https://wiki.kolmafia.us/index.php?title=Custom_Combat_Script&amp;diff=4438"/>
		<updated>2013-06-10T10:24:19Z</updated>

		<summary type="html">&lt;p&gt;PsyMar: example script calculated several things wrong; immaculate seasoning does not override gazpacho&amp;#039;s, for example.  Also, saucespheres aren&amp;#039;t needed for splash, but being a sauceror is&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{TOCright}}&lt;br /&gt;
== Basic CCS ==&lt;br /&gt;
A Custom Combat Script (CCS) is a way of instructing mafia how to handle combat, round by round. For example, a simple CCS would be to tell mafia to pickpocket on round 1, then cast entangling noodles on round 2 and finally on rounds 3+ to use shieldbutt. If it is unable to carry out one of those steps, then that step will be skipped. For instance, if the character failed to get initiative, then pickpocket will be skipped and the character will go straight to entangling noodles. That CCS would look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;border: solid 1px black; padding: 1em; margin:0px 20px;&amp;quot;&amp;gt;&lt;br /&gt;
[ default ]&amp;lt;br /&amp;gt;&lt;br /&gt;
try to steal an item&amp;lt;br /&amp;gt;&lt;br /&gt;
skill entangling noodles&amp;lt;br /&amp;gt;&lt;br /&gt;
skill shieldbutt&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you wanted to treat different monsters differently, that can be accommodated also. For instance, the following CCS will attempt to cast Transcendent Olfaction upon Black Knights while treating all other monsters differently. If the character currently has &amp;quot;On the Trail&amp;quot; then that line will be skipped.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;border: solid 1px black; padding: 1em; margin:0px 20px;&amp;quot;&amp;gt;&lt;br /&gt;
[ Black Knight ]&amp;lt;br /&amp;gt;&lt;br /&gt;
try to steal an item&amp;lt;br /&amp;gt;&lt;br /&gt;
skill transcendent olfaction&amp;lt;br /&amp;gt;&lt;br /&gt;
skill entangling noodles&amp;lt;br /&amp;gt;&lt;br /&gt;
skill shieldbutt&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[ default ]&amp;lt;br /&amp;gt;&lt;br /&gt;
try to steal an item&amp;lt;br /&amp;gt;&lt;br /&gt;
skill entangling noodles&amp;lt;br /&amp;gt;&lt;br /&gt;
skill shieldbutt&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that when you use a CCS, your CLI will report &amp;quot;character executes a macro!&amp;quot; because the CCS is converted into a macro to save on page loads&lt;br /&gt;
&lt;br /&gt;
=== Available Commands ===&lt;br /&gt;
* attack&lt;br /&gt;
* skill&lt;br /&gt;
* item, use&lt;br /&gt;
* try to steal an item, pickpocket&lt;br /&gt;
* summon pastamancer ghost&lt;br /&gt;
* jiggle chefstaff&lt;br /&gt;
* combo {followed by one of the following}&lt;br /&gt;
** Disco Concentration, Disco Nirvana, Disco Inferno, Disco Bleeding, Disco Blindness&lt;br /&gt;
** Rave Knockout, Rave Bleeding, Rave Concentration, Rave Steal, Rave Nirvana, Rave Stats&lt;br /&gt;
** [http://kolmafia.us/showthread.php?5709-Add-rave-combo-learning-to-quot-special-action-quot&amp;amp;p=42107&amp;amp;viewfull=1#post42107 random rave]&lt;br /&gt;
* abort&lt;br /&gt;
* abort after&lt;br /&gt;
* section [section name]&lt;br /&gt;
* special&lt;br /&gt;
* delevel&lt;br /&gt;
* skip&lt;br /&gt;
* note&lt;br /&gt;
* twiddle&lt;br /&gt;
&lt;br /&gt;
== Macros in CCS ==&lt;br /&gt;
Macros may be used in a Custom Combat Script in addition to the basic commands. Any line in quotes  and any macro command used in a CCS will be made into part of the macro which KoLmafia is passing to KoL. You can find an primer on all KoL&#039;s macros at {{kolwiki|Combat Macros}}.&lt;br /&gt;
&lt;br /&gt;
Also there is a section in the CCS called &amp;quot;global prefix&amp;quot; which will be part of every combat macro KoLmafia generates, regardless of the monster encountered. &lt;br /&gt;
&lt;br /&gt;
=== Example of CCS Macro ===&lt;br /&gt;
Here&#039;s an example of a CCS that generates a macro which will cause KoL to wait for a hobo monkey to steal meat from your enemy before launching attacks.&lt;br /&gt;
&amp;lt;div style=&amp;quot;border: solid 1px black; padding: 1em; margin:0px 20px;&amp;quot;&amp;gt;&lt;br /&gt;
[ default ]&amp;lt;br /&amp;gt;&lt;br /&gt;
sub monkey_stasis&amp;lt;br /&amp;gt;&lt;br /&gt;
:while !match &amp;quot;climbs up and sits on your shoulder&amp;quot; &amp;amp;&amp;amp; !pastround 20 &amp;amp;&amp;amp; !hppercentbelow 20&lt;br /&gt;
::call stasis_item&lt;br /&gt;
:endwhile&lt;br /&gt;
endsub&amp;lt;br /&amp;gt;&lt;br /&gt;
call monkey_stasis&amp;lt;br /&amp;gt;&lt;br /&gt;
attack&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[ global prefix ]&amp;lt;br /&amp;gt;&lt;br /&gt;
scrollwhendone&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;quot;abort missed 5&amp;quot;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;quot;abort pastround 27&amp;quot;&amp;lt;br /&amp;gt;&lt;br /&gt;
sub stasis_item&amp;lt;br /&amp;gt;&lt;br /&gt;
:if hascombatitem facsimile dictionary&lt;br /&gt;
::item facsimile dictionary&lt;br /&gt;
::goto _endstasisitem&lt;br /&gt;
:endif&lt;br /&gt;
:if hascombatitem seal tooth&lt;br /&gt;
::item seal tooth&lt;br /&gt;
::goto _endstasisitem&lt;br /&gt;
:endif&lt;br /&gt;
:if hascombatitem spices&lt;br /&gt;
::item spices&lt;br /&gt;
::goto _endstasisitem&lt;br /&gt;
:endif&lt;br /&gt;
:if hascombatitem spectre scepter&lt;br /&gt;
::item spectre scepter&lt;br /&gt;
::goto _endstasisitem&lt;br /&gt;
:endif&lt;br /&gt;
:if hascombatitem dictionary&lt;br /&gt;
::item dictionary&lt;br /&gt;
::goto _endstasisitem&lt;br /&gt;
:endif&lt;br /&gt;
:if hascombatitem fat stacks of cash&lt;br /&gt;
::item fat stacks of cash&lt;br /&gt;
::goto _endstasisitem&lt;br /&gt;
:endif&lt;br /&gt;
:&amp;quot;abort &amp;quot;No infinite use items detected!&amp;quot; &amp;quot;&lt;br /&gt;
:mark _endstasisitem&lt;br /&gt;
endsub&amp;lt;br /&amp;gt;&lt;br /&gt;
sub stasis&amp;lt;br /&amp;gt;&lt;br /&gt;
:while !pastround 20 &amp;amp;&amp;amp; !hppercentbelow 20 &amp;amp;&amp;amp; mppercentbelow 99&lt;br /&gt;
::call stasis_item&lt;br /&gt;
:endwhile&lt;br /&gt;
endsub&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Concerns for macros in CCS ===&lt;br /&gt;
*A macro&#039;s abort command needs to be encased in quotes because abort is also a legal CCS command. That&#039;s why all aborts in the previous example were quoted. &lt;br /&gt;
&lt;br /&gt;
*If a comment is the last line in a CCS, that will be used as your finishing attack even though it does nothing. Never conclude a CCS with a macro comment or it will abort to the mini-browser with a warning from KoL that you executed 37 commands in a row without taking an action.&lt;br /&gt;
&lt;br /&gt;
== Consult Scripts ==&lt;br /&gt;
While a CCS may seem reasonably flexible, sometimes you will want to do something too complicated to express in that format. For instance if you want your character to take different actions based on your characters current stats or current monster level, a consult script can automatically figure it out. There are few limits to what a consult script can enable. The downside to using a consult script is that KoLmafia will not be able to generate a combat macro to pass to KoL. As a result multi-round combat will take somewhat longer.&lt;br /&gt;
&lt;br /&gt;
A consult script is called by using the &amp;quot;consult&amp;quot; command in your CCS, as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;border: solid 1px black; padding: 1em; margin:0px 20px;&amp;quot;&amp;gt;&lt;br /&gt;
[ default ]&amp;lt;br /&amp;gt;&lt;br /&gt;
consult myscript.ash&amp;lt;br /&amp;gt;&lt;br /&gt;
attack&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The main() function in the ASH script being consulted must accept three parameters:&lt;br /&gt;
&lt;br /&gt;
 void main(int round, monster mob, string combat)&lt;br /&gt;
&lt;br /&gt;
These values will be supplied by mafia when the consult script is called.&lt;br /&gt;
&lt;br /&gt;
=== Example of a Consult Script ===&lt;br /&gt;
This example will attempt to maximize use of a Sauceror&#039;s spells as a Sauceror by making use of sauce splash effects when they can be used.&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin-bottom: 1em; border: dashed 1px green; padding: 1em; margin:0px 20px;&amp;quot;&amp;gt;&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
// Save this as SauceSplash.ash&lt;br /&gt;
boolean sauceSplash() {&lt;br /&gt;
   if(!my_class() == $class[Sauceror])&lt;br /&gt;
         return false;&lt;br /&gt;
   int normal = numeric_modifier(&amp;quot;spell damage&amp;quot;);&lt;br /&gt;
   if(normal &amp;gt;= 25)&lt;br /&gt;
      return true;&lt;br /&gt;
   int cold = numeric_modifier(&amp;quot;cold spell damage&amp;quot;);&lt;br /&gt;
   int hot = numeric_modifier(&amp;quot;hot spell damage&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
   #deal with monsters weak to cold&lt;br /&gt;
   if(((((monster_element() == $element[stench]) || (monster_element() == $element[sleaze]))&lt;br /&gt;
     &amp;amp;&amp;amp; have_skill($skill[Immaculate Seasoning]))&lt;br /&gt;
     || have_equipped($item[Gazpacho&#039;s Glacial Grimoire]))&lt;br /&gt;
     &amp;amp;&amp;amp; cold + normal &amp;gt;= 25)&lt;br /&gt;
        return true;&lt;br /&gt;
   #deal with monsters weak to hot&lt;br /&gt;
   else if((((((monster_element() == $element[cold]) || (monster_element() == $element[spooky]))&lt;br /&gt;
     &amp;amp;&amp;amp; have_skill($skill[Immaculate Seasoning]))&lt;br /&gt;
     || have_equipped($item[Codex of Capsaicin Conjuration])&lt;br /&gt;
     || have_equipped($item[Ol&#039; Scratch&#039;s manacles])&lt;br /&gt;
     || have_equipped($item[Ol&#039; Scratch&#039;s ash can]))&lt;br /&gt;
     &amp;amp;&amp;amp; hot + normal &amp;gt;= 25)&lt;br /&gt;
   #deal with monsters weak to neither (hot/non-aligned)&lt;br /&gt;
   else if(have_skill($skill[Immaculate Seasoning])&lt;br /&gt;
      &amp;amp;&amp;amp; cold != hot &amp;amp;&amp;amp; max(cold, hot) + normal &amp;gt;= 25)&lt;br /&gt;
         return true;&lt;br /&gt;
   else return false;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void main(int initround, monster foe, string page) {&lt;br /&gt;
   if(have_effect($effect[Burning Soul]) || have_effect($effect[Soul Freeze]) || !sauceSplash())&lt;br /&gt;
      use_skill($skill[Saucegeyser]);&lt;br /&gt;
   else&lt;br /&gt;
      use_skill($skill[Wave of Sauce]);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This consult script can then be integrated into a CCS like this:&lt;br /&gt;
&amp;lt;div style=&amp;quot;border: solid 1px black; padding: 1em; margin:0px 20px;&amp;quot;&amp;gt;&lt;br /&gt;
[ default ]&amp;lt;br /&amp;gt;&lt;br /&gt;
consult SauceSplash.ash&amp;lt;br /&amp;gt;&lt;br /&gt;
attack&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Parts of a Combat Consultation Script ===&lt;br /&gt;
As you can see in the above example, a consultation script is called with three parameters.&lt;br /&gt;
*The first parameter is the round of combat that the script is called. Sometimes it is important to keep track of the round. This is particularly important to keep from losing the fight by going over 30 rounds.&lt;br /&gt;
*The second parameter is the monster that you are fighting. This is important because it enables you to take different actions for different monsters.&lt;br /&gt;
*The third parameter is the text of the page. This is important because it enables you to examine every detail of the fight as it is taking place. It can be analyzed for potential actions, damage that you deal to a monster and all other events.&lt;br /&gt;
&lt;br /&gt;
All possible actions you can take in a round of combat are listed under [[In-combat Consulting]].&lt;br /&gt;
&lt;br /&gt;
=== Resolution of a Combat Consultation Script ===&lt;br /&gt;
The consult script can automate as many, or as few rounds of combat as desired to achieve its goal. When it finishes executing, if the monster is not yet dead, then the CCS will continue combat from the current round. Note that the current round is not always the next line in a script. For instance, if the consult script is called at round 1 and executes three actions, then it will return to the CCS at round 4. This is why most CCSs containing consult script prefer to have only a line after the consult script, usually a simple method of killing a monster.&lt;br /&gt;
&lt;br /&gt;
=== Macros in Consult Scripts ===&lt;br /&gt;
It is possible for a consult script to submit a macro. As a simple example, if your consult script wants to submit a macro that simply attacks the monster until the combat ends...&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin-bottom: 1em; border: dashed 1px green; padding: 1em; margin:0px 20px;&amp;quot;&amp;gt;&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
string macro = &amp;quot;attack; repeat&amp;quot;&lt;br /&gt;
visit_url(&amp;quot;fight.php?action=macro&amp;amp;macrotext=&amp;quot; + url_encode(macro) ,true,true);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Between macro commands you need to insert either /n or a semi-colon as in the above example. Your submitted macro can be as complicated as you wish.&lt;br /&gt;
&lt;br /&gt;
== Employ Scripts ==&lt;br /&gt;
&amp;lt;div style=&amp;quot;padding: 1em; border: solid 1px red; color: red; font-weight: bold;&amp;quot;&amp;gt;Please note! This section is speculative; Employ Scripts have not yet been implemented.&amp;lt;/div&amp;gt;&lt;br /&gt;
An employ script is a like a consultation script, with benefits. While a consultation script operates turn-by-turn, an employ script operates only at the beginning of the combat and generates a combat macro.&lt;br /&gt;
&lt;br /&gt;
Employ scripts do not yet exist in KolMafia at this time, but they are a goal that jasonharper is working towards as he [http://kolmafia.us/showthread.php?4098-Dynamic-Combat-in-the-Age-of-Macros describes on the mafia forum].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is currently proposed that they will have the following format:&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;string main( string opponent, string pageText, string macroSoFar, string parameter )&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* opponent is the name of the monster being fought, just as in a consult script or combat filter function.&lt;br /&gt;
* pageText is the raw HTML of the initial combat page. This isn&#039;t necessarily going to be useful (since it&#039;s a one-time snapshot), however you may want to examine the Skills popup to see what conditionally-available skills are actually available.&lt;br /&gt;
* macroSoFar is the current text of the macro being built - a mafia-generated header with some useful subroutines defined, followed by macro translations of all the prior lines in the CCS.&lt;br /&gt;
* parameter contains any extra text from the CCS line; it could be used to customize the behavior of the script, more conveniently than using a &amp;quot;note&amp;quot; line with a consult script. It also serves the less obvious purpose of making the parameter count something other than 3, so that mistakenly attempting to employ a consult script, or consult an employ script, will fail before any code runs.&lt;br /&gt;
* The return value entirely replaces the macro being built. It would probably be an error for this to be any shorter than the original value of macroSoFar.&lt;br /&gt;
&lt;br /&gt;
The simplest thing an employ script could do is to append some commands to macroSoFar, and return that. Other possibilities include:&lt;br /&gt;
* It could look back through the previously-generated macro commands to decide what to do. For example, it could refrain from adding a &amp;quot;pickpocket&amp;quot; action if that has already been done&lt;br /&gt;
* If it wanted to set up a global abort condition, active throughout the combat, it could insert the command at the beginning of the macro.&lt;br /&gt;
* There will be a subroutine called &amp;quot;mafiaround&amp;quot; defined in the header, and called before every combat action to handle things like automatic antidote use. The script could insert commands into that subroutine, for example to implement an eye color check for using He-Boulder major rays.&lt;br /&gt;
* There will likely be other defined subroutines for the script to call or modify.&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting]]&lt;/div&gt;</summary>
		<author><name>PsyMar</name></author>
	</entry>
</feed>