Difference between revisions of "Miscellaneous Functions"

From Kolmafia
Jump to navigation Jump to search
imported>Raeith
(Add "gCLI Command Functions" section)
 
(295 intermediate revisions by more than 100 users not shown)
Line 1: Line 1:
== Part 6 - Miscellaneous ==
+
{{TOCright}}
<p><em>Mostly internal stuff. Some good for everyone, some only for ASH wizards.</em></p>
+
== Chat Functions ==
 +
{{Flink|void|chat_clan|string}}
 +
{{Flink|void|chat_clan|string|string|desc=Sends a message to clan chat.}}
 +
{{Flink|void|chat_macro|string|desc=Submits a chat macro to KoL.}}
 +
{{Flink|void|chat_notify|string|string|desc=Sends a notification to the player's own chat.}}
 +
{{Flink|void|chat_private|string|string|desc=Sends a private message to another player.}}
 +
{{Flink|boolean|is_online|string|desc=Check to see if a player is online.}}
 +
{{Flink|boolean [string]|who_clan|desc=Returns a list of whom is in your clan and if they are in chat.}}
 +
{{Flink|boolean|can_faxbot|monster|desc=Check to see if a monster can be faxed.}}
 +
{{Flink|boolean|faxbot|monster|desc=Attempts to receive a fax of a given monster.}}
  
<p><strong>void print( string helloworld )</strong><br />
+
== Debugging Functions ==
Prints the given string to the graphical CLI window and to the status line of the main Adventuring window</p>
+
{{Flink|void|disable|string|desc=Disables the specified function.}}
 +
{{Flink|void|enable|string|desc=Enables the specified function.}}
 +
{{Flink|buffer|load_html|string|desc=Works like visit_url(), but for debugging.}}
 +
{{Flink|string|make_url|string|boolean|boolean|desc=Crafts the URL to visit.}}
  
<p><strong>boolean cli_execute( string command )</strong><br />
+
== File Input/Output Functions ==
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 />
+
{{FunctionEmbed|buffer_to_file|format=signature|desc=yes}}
See the [http://kolmafia.sourceforge.net/scripting.html CLI manual] for more details.</p>
+
{{FunctionEmbed|file_to_array|format=signature|desc=yes}}
 +
{{FunctionEmbed|file_to_buffer|format=signature|desc=yes}}
 +
{{Flink|boolean|file_to_map|string|aggregate|desc=Loads a map from a tab-delimited text file.}}
 +
{{Flink|boolean|map_to_file|aggregate|string|desc=Saves a map to a tab-delimited text file.}}
  
<p><strong>void wait( int delay )</strong><br />
+
== gCLI Command Functions ==
Does nothing for the desired number of seconds.</p>
+
{{FunctionEmbed|cli_execute|format=signature|desc=yes}}
 +
{{FunctionEmbed|cli_execute_output|format=signature|desc=yes}}
  
<p><strong>string get_property( string key )<br />
+
== Map Management Functions ==
boolean set_property( string key, string value )</strong><br />
+
''Note: Information about maps (including creating, assigning, and removing keys, can be found at [[Data Structures#Maps|Map Data Structures]].''
Gets or sets a stored property from your character&#8217;s .kcs file.<br />
 
The KoLmafia [http://www.wiki.kolmafia.us/index.php/%28ASHRM%29_KoLMafia_Properties properties] page contains details on many of the keys that are available for access.</p>
 
  
<p><strong>string boolean_to_string( boolean flag )<br />
+
{{Flink|int|count|aggregate|desc=Returns the number of defined keys for the specified aggregate.}}
string int_to_string( int number )<br />
+
{{Flink|void|clear|aggregate|desc=Removes all keys from the specified aggregate.}}
string float_to_string( float number )<br />
 
string item_to_string( item it )<br />
 
string zodiac_to_string( zodiac sign )<br />
 
string location_to_string( location place )<br />
 
string familiar_to_string( class cl )<br />
 
string class_to_string( class cl )<br />
 
string stat_to_string( stat st )<br />
 
string skill_to_string( skill sk )<br />
 
string effect_to_string( effect ef )<br />
 
string element_to_string( element el )<br />
 
string slot_to_string( slot sl )<br />
 
string monster_to_string( monster eek )</strong><br />
 
Converts in-game variables to printable counterparts. The print command will cast non-string values properly now, but these are still useful for building URLs and setting properties.</p>
 
  
<p><strong>boolean string_to_boolean( string str )<br />
+
== Time Functions ==
int string_to_int( string str )<br />
+
{{Flink|string|format_date_time|string|string|string|desc=Reformats dates.}}
float string_to_float( string str )<br />
+
{{Flink|int|gameday_to_int|desc=Returns the current KoL date as an integer.}}
item string_to_item( string str )<br />
+
{{Flink|string|gameday_to_string|desc=Returns the current KoL date as a string.}}
zodiac string_to_zodiac( string str )<br />
+
{{Flink|int|gametime_to_int|desc=Returns the current KoL time in ms as an integer.}}
location string_to_location( string str )<br />
+
{{Flink|string|now_to_string|string|desc=Returns current local time/date in SimpleDateFormat format.}}
familiar string_to_familiar( string str )<br />
+
{{Flink|string|time_to_string|desc=Returns the current local time in HH:mm:ss z format.}}
class string_to_class( string str )<br />
+
{{Flink|string|today_to_string|desc=Returns the current local day in ISO format.}}
stat string_to_stat( string str )<br />
 
skill string_to_skill( string str )<br />
 
effect string_to_effect( string str )<br />
 
slot string_to_slot( string str )<br />
 
element string_to_element( string str )<br />
 
monster string_to_monster( string str )</strong><br />
 
Converts strings to ASH variables.  Useful for converting the result of a get_property() call intoa legitimate value.</p>
 
  
<p><strong>int item_to_int( item it )<br />
+
== SVN Functions ==
int skill_to_int ( skill sk )<br />
+
''There is much additional information in the [[SVN Primer]]''.
int effect_to_int ( effect eff )<br />
+
{{Flink|boolean|svn_exists|string|desc=Returns true if a valid working copy named projectname exists in the svn/ folder.}}
int familiar_to_int ( familiar pet )<br />
+
{{Flink|boolean|svn_at_head|string|desc=Returns true if projectname exists, is a valid working copy, and is currently at the same revision number as the repository.}}
int slot_to_int ( slot sl )<br />
+
{{Flink|record|svn_info|string|desc=Returns a record containing additional information about the given projectname: svnurl, last author, last revision, last change date.}}
int element_to_int ( element el )</strong><br />
 
Converts the ASH-based object into the number that will be recognized by the KoL server. Needed when you&#8217;re building raw URLs from time to time.</p>
 
  
<p><strong>item int_to_item( int nItem )<br />
+
== User Interaction ==
skill int_to_skill ( int nSkill )<br />
+
{{Flink|void|print|string|{{opt|string}}|desc=Prints to CLI and status line of Adventuring window, optionally in a specified color.}}
effect int_to_effect ( int nEffect )<br />
+
{{Flink|void|print_html|string|desc=Prints to CLI, parsing any included html.}}
familiar int_to_familiar ( int nFamiliar )<br />
+
{{Flink|void|logprint|string|desc=Prints to the session log.}}
slot int_to_slot ( int nSlot )<br />
+
{{Flink|void|wait|int}}
element int_to_element ( int nElement )</strong><br />
+
{{Flink|void|waitq|int|desc=Sleeps for the specified number of seconds.}}
Converts the KoL-based number into an associated ASH object. These aren&#8217;t the commands you&#8217;re looking for. You can go about your business.</p>
+
{{Flink|boolean|user_confirm|string|desc=Allows user input in Y/N format.}}
  
<p><strong>void file_to_map( string file_to_load, map map_to_fill )<br />
+
== Property Functions ==
void map_to_file( map map_to_save, string file_to_write )</strong><br />
+
{{Flink|boolean [string]|get_all_properties|string|boolean|desc=Returns a map of all user or global properties.}}
Loads and saves maps as tab-delimited text files.</p>
+
{{FunctionEmbed|property_exists|format=signature|desc=yes}}
 +
{{FunctionEmbed|property_has_default|format=signature|desc=yes}}
 +
{{FunctionEmbed|property_default_value|format=signature|desc=yes}}
 +
{{Flink|string|get_property|string}}
 +
{{Flink|string|get_property|string|boolean|desc=Gets a global or user preference as appropriate.}}
 +
{{Flink|void|set_property|string|string|desc=Sets a global or user preference as appropriate.}}
 +
{{FunctionEmbed|remove_property|format=signature|desc=yes}}
 +
{{FunctionEmbed|rename_property|format=signature|desc=yes}}
  
<p><strong>int random( int range )</strong><br />
+
== Other Functions ==
Generates a random integer between 0 and (range-1) inclusive.</p>
+
{{FunctionEmbed|abort|format=signature|desc=yes}}
 +
{{FunctionEmbed|all_monsters_with_id|format=signature|desc=yes}}
 +
{{Flink|void|batch_open|desc=Used to mark the beginning of a block of functions to operate in batch mode (see page for {{f|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).}}
 +
{{Flink|int|get_revision|desc=Returns the current KoLmafia revision number.}}
 +
{{Flink|string|get_version|desc=Returns the most recent KoLmafia version.}}
 +
{{Flink|string|get_player_id|string|desc=Returns the user id number of a given player.}}
 +
{{FunctionEmbed|is_dark_mode|format=signature|desc=yes}}
 +
{{Flink|string|to_json|aggregate|desc=Converts a simple aggregate into JSON.}}
  
<p><strong>int round( float ratio )<br />
+
Additional functions that are considered not really to be ash functions are available in [[Miscellaneous ASH Features#Special Syntax Functions|Misc ASH Features]]
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 />
+
[[Category:Scripting]]
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>
 

Latest revision as of 14:55, 23 December 2020

Chat Functions

void chat_clan( string )

void chat_clan( string, string )

Sends a message to clan chat.

void chat_macro( string )

Submits a chat macro to KoL.

void chat_notify( string, string )

Sends a notification to the player's own chat.

void chat_private( string, string )

Sends a private message to another player.

boolean is_online( string )

Check to see if a player is online.

boolean [string] who_clan()

Returns a list of whom is in your clan and if they are in chat.

boolean can_faxbot( monster )

Check to see if a monster can be faxed.

boolean faxbot( monster )

Attempts to receive a fax of a given monster.


Debugging Functions

void disable( string )

Disables the specified function.

void enable( string )

Enables the specified function.

buffer load_html( string )

Works like visit_url(), but for debugging.

string make_url( string, boolean, boolean )

Crafts the URL to visit.


File Input/Output Functions

boolean buffer_to_filebuffer, string )

Saves a buffer to a text file. Returns true on success, false on failure.

string [int] file_to_arraystring )

Reads data from a text file and returns a map of strings containing each line.

buffer file_to_bufferstring )

Loads the entire contents of a text file into a buffer.

boolean file_to_map( string, aggregate )

Loads a map from a tab-delimited text file.

boolean map_to_file( aggregate, string )

Saves a map to a tab-delimited text file.


gCLI Command Functions

boolean cli_executestring )

Executes a string as a gCLI command. Returns true on success, false on failure.

string cli_execute_outputstring )

Executes a gCLI command, capturing and returning the gCLI output.

Map Management Functions

Note: Information about maps (including creating, assigning, and removing keys, can be found at Map Data Structures.

int count( aggregate )

Returns the number of defined keys for the specified aggregate.

void clear( aggregate )

Removes all keys from the specified aggregate.


Time Functions

string format_date_time( string, string, string )

Reformats dates.

int gameday_to_int()

Returns the current KoL date as an integer.

string gameday_to_string()

Returns the current KoL date as a string.

int gametime_to_int()

Returns the current KoL time in ms as an integer.

string now_to_string( string )

Returns current local time/date in SimpleDateFormat format.

string time_to_string()

Returns the current local time in HH:mm:ss z format.

string today_to_string()

Returns the current local day in ISO format.


SVN Functions

There is much additional information in the SVN Primer.

boolean svn_exists( string )

Returns true if a valid working copy named projectname exists in the svn/ folder.

boolean svn_at_head( string )

Returns true if projectname exists, is a valid working copy, and is currently at the same revision number as the repository.

record svn_info( string )

Returns a record containing additional information about the given projectname: svnurl, last author, last revision, last change date.


User Interaction

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.

void wait( int )

void waitq( int )

Sleeps for the specified number of seconds.

boolean user_confirm( string )

Allows user input in Y/N format.


Property Functions

boolean [string] get_all_properties( string, boolean )

Returns a map of all user or global properties.

boolean property_existsstring, boolean? )

Checks whether a property exists.

boolean property_has_defaultstring )

Checks if a property has a built-in default value.

string property_default_valuestring )

Returns the default value of a property, or an empty string if a default value does not exist.

string get_property( string )

string get_property( string, boolean )

Gets a global or user preference as appropriate.

void set_property( string, string )

Sets a global or user preference as appropriate.

string remove_propertystring, boolean? )

Removes or resets a property and returns its previous value.

boolean rename_propertystring, string )

Renames a property. Returns true on success, false on failure.

Other Functions

void abortstring? )

Immediately halts the current script and all queued functions.

boolean [monster] all_monsters_with_id()

Returns a map of all monsters that have a non-zero monster ID.

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).

int get_revision()

Returns the current KoLmafia revision number.

string get_version()

Returns the most recent KoLmafia version.

string get_player_id( string )

Returns the user id number of a given player.

boolean is_dark_mode()

Checks if the current KoLmafia theme is dark mode.

string to_json( aggregate )

Converts a simple aggregate into JSON.


Additional functions that are considered not really to be ash functions are available in Misc ASH Features