Difference between revisions of "Miscellaneous Functions"

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
imported>StDoodle
Line 1: Line 1:
== Part 7 - Miscellaneous ==
+
{{Flink|void|abort|{{opt|string}}|desc=Aborts the current script with an optional message.}}
<p><em>Mostly internal stuff. Some good for everyone, some only for ASH wizards.</em></p>
+
{{Flink|void|print|string|{{opt|string}}|desc=Prints to CLI and status line of Adventuring window, optionally in a specified color.}}
 
+
{{Flink|void|print_html|string|desc=Prints to CLI, parsing any included html.}}
<p><strong>void print( string output )</strong><br />
+
{{Flink|void|logprint|string|desc=Prints to the session log.}}
<strong>void print( string output, string color )</strong><br />
+
{{Flink|boolean|cli_execute|string|desc=Executes the given command as if it were entered into the CLI.}}
Prints <i>output</i> to the CLI buffer and displays it in the status line of the main Adventuring window.  If <i>color</i> is specified any HTML in <i>output</i> is escaped and the string is wrapped in a font tag before being printed.</p>
+
{{Flink|void|wait|int|desc=Sleeps for the specified number of seconds.}}
 
+
{{Flink|string|get_property|string|desc=Gets a global or user preference as appropriate.}}
<p><strong>void logprint( string output )</strong><br />
+
{{Flink|string|set_property|string|desc=Sets a global or user preference as appropriate.}}
Prints the output to the session log.</p>
+
{{Flink|void|batch_open|desc=Used to mark the beginning of a block of functions to operate in batch mode (see page for [[batch_close|batch_close()]] for details).}}
 
+
{{Flink|boolean|batch_close|desc=Used to mark the end of a block of functions to operate in batch mode (see page for details).}}
<p><strong>void print_html( string output )</strong> <br />
+
{{Flink|boolean|file_to_map|string|aggregate|desc=Loads a map from a tab-delimited text file.}}
Prints output to the CLI buffer, and parses any html.</p>
+
{{Flink|boolean|map_to_file|string|aggregate|desc=Saves a map to a tab-delimited text file.}}
 
+
{{Flink|int|count|aggregate|desc=Returns the number of defined keys for the specified aggregate.}}
<p><strong>boolean cli_execute( string command )</strong><br />
+
{{Flink|void|clear|aggregate|desc=Removes all keys from the specified aggregate.}}
Executes the given command as if it were entered into the graphical CLI window. This can be used for CLI commands or, if you&#8217;re careful and not an asshat, for raw URLs.<br />
+
{{Flink|int|random|int|desc=Generates a random integer between 0 and 1 less than the specified number, inlcusive (produces an error when supplied a value of 1).}}
See the [http://kolmafia.sourceforge.net/scripting.html CLI manual] for more details.<br />
+
{{Flink|int|ceil|float|desc=Returns the next highest value of the specified number as an integer (returns the number if integer form if decimal portion is equal to 0).
<em>Sample</em>:[[%28ASHRM%29_Code_Samples#Sample_4:_Hedging|Hedging]]</p>
+
{{Flink|int|floor|float|desc=Returns the next lowest value of the specified number as an integer (returns the number if integer form if decimal portion is equal to 0).
 
+
{{Flink|int|truncate|float|desc=Returns the decimal-stripped value of the specified number as an integer (returns the number if integer form if decimal portion is equal to 0).
<p><strong>void wait( int delay )</strong><br />
+
{{Flink|float|square_root|float|desc=Returns the square root of the specified value.}}
Sleeps for <i>delay</i> seconds.</p>
+
{{Flink|void|disable|string|desc=Disables the specified function (for debugging purposes).}}
 
+
{{Flink|void|enable|string|desc=Enables the specified function (for debugging purposes).}}
<p><strong>string get_property( string key )<br />
 
boolean set_property( string key, string value )</strong><br />
 
Gets or sets a stored property from your character&#8217;s .kcs file.<br />
 
The KoLmafia [[%28ASHRM%29_KoLMafia_Properties|properties]] page contains details on many of the keys that are available for access.<br />
 
<em>Sample</em>:[[%28ASHRM%29_Code_Samples#Sample_2:_Battlefield_gather|Battlefield_gather]]</p>
 
 
 
<p><strong>boolean file_to_map( string file_to_load, map map_to_fill )<br />
 
boolean map_to_file( map map_to_save, string file_to_write )</strong><br />
 
Loads and saves maps as tab-delimited text files.</p>
 
 
 
<p><strong>int random( int range )</strong><br />
 
Generates a random integer between 0 and (range-1) inclusive.</p>
 
 
 
<p><strong>int round( float ratio )<br />
 
int floor( float ratio )<br />
 
int ceil( float ratio )<br />
 
int truncate( float ratio )</strong><br />
 
Returns an integer near the given real number.  Respectively, it returns the nearest, next lowest, next highest, and decimal-stripped integer.</p>
 
 
 
<p><strong>int count( map )</strong><br />
 
Returns the number of defined keys for the aggregate.</p>
 
 
 
<p><strong>void clear( map )</strong><br />
 
Remove all keys from a map. </p>
 
 
 
<p><strong>void disable( string function_name )<br />
 
void enable( string function_name )</strong><br />
 
For debugging purposes disables or enables the indicated function</p>
 
 
 
<p><strong>float square_root( float value )</strong><br />
 
returns the square root of the passed value</p>
 
 
 
<p><strong>string today_to_string()</strong><br />
 
Returns today&#8217;s (real-world) date in the form yyyymmdd. It is based on your computer&#8217;s system date</p>
 
 
 
<p>'''void [[batch_open()]]'''</p>
 
 
 
<p>'''boolean [[batch_close()]]'''</p>
 
 
 
<p>'''void [[abort|abort()]]'''<br>
 
[[void]] [[abort]]({{Param|string|message}})<br />
 
Aborts the current script with an optional message.</p>
 

Revision as of 18:46, 4 March 2010

void abort( [string] )

Aborts the current script with an optional message.

void print( string, [string] )

Prints to CLI and status line of Adventuring window, optionally in a specified color.

void print_html( string )

Prints to CLI, parsing any included html.

void logprint( string )

Prints to the session log.

boolean cli_execute( string )

Executes the given command as if it were entered into the CLI.

void wait( int )

Sleeps for the specified number of seconds.

string get_property( string )

Gets a global or user preference as appropriate.

string set_property( string )

Sets a global or user preference as appropriate.

void batch_open()

Used to mark the beginning of a block of functions to operate in batch mode (see page for batch_close() for details).

boolean batch_close()

Used to mark the end of a block of functions to operate in batch mode (see page for details).

boolean file_to_map( string, aggregate )

Loads a map from a tab-delimited text file.

boolean map_to_file( string, aggregate )

Saves a map to a tab-delimited text file.

int count( aggregate )

Returns the number of defined keys for the specified aggregate.

void clear( aggregate )

Removes all keys from the specified aggregate.

int random( int )

Generates a random integer between 0 and 1 less than the specified number, inlcusive (produces an error when supplied a value of 1).

{{Flink|int|ceil|float|desc=Returns the next highest value of the specified number as an integer (returns the number if integer form if decimal portion is equal to 0). {{Flink|int|floor|float|desc=Returns the next lowest value of the specified number as an integer (returns the number if integer form if decimal portion is equal to 0). {{Flink|int|truncate|float|desc=Returns the decimal-stripped value of the specified number as an integer (returns the number if integer form if decimal portion is equal to 0).

float square_root( float )

Returns the square root of the specified value.

void disable( string )

Disables the specified function (for debugging purposes).

void enable( string )

Enables the specified function (for debugging purposes).