Cli execute: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
mNo edit summary
imported>StDoodle
No edit summary
Line 1: Line 1:
'''[[boolean]] cli_execute( [[string]] command )'''
{{
Executes the given command as a CLI command, rather than ASH.
#vardefine:name|cli_execute}}{{
#vardefine:return_type|boolean}}{{


<pre>
FunctionPage|
// snippet from my aftercore.ash script
name={{#var:name}}|
    cli_execute("outfit "+consumption_outfit);
function_category=Miscellaneous|
   
    if (use_milk_of_mag) cli_execute("use milk of magnesium");
   
    foreach i in food_items
    {
   
      cli_execute("eat "+food_items[i]);
   
    }
   
    foreach i in booze_items
    {
   
      cli_execute("drink "+booze_items[i]);
   
    }
   
    foreach i in spleen_items
    {
   
      cli_execute("use "+spleen_items[i]);
   
    }
   
    if (switch_ode_polka)
    {
      cli_execute("uneffect ode to booze");
      cli_execute("nuns");
      cli_execute("cast 35 polka of plenty");
    }
</pre>


Note that you can speed things up (and possibly reduce the number of HTTP requests sent to KoL) by combining multiple requests in one command:
function1={{Function|
<pre>
name={{#var:name}}|
    # from bottom of above code...
aggregate={{#var:aggregate}}|
    if (switch_ode_polka)
return_type={{#var:return_type}}|
    {
return_also={{#var:return_also}}|
      cli_execute{
parameter1={{Param|string|command}}|
        uneffect ode to booze;
p1desc={{Pspan|command}} is a cli command or commands to execute|
        nuns;
}}|
        cast 35 polka of plenty;
      } # note the lack of a semicolon here!
    }


</pre>
function_description=This function passes the parameter {{pspan|command}} on to KoLmafia's CLI, which will execute it as if it were typed in through the normal interface. This function will return true if the CLI command executed properly, and false if it was unable to do so (for example, trying to execute an adventuring command while drunk). Though it's considered a "best practice" to use built-in ASH functions when possible, there are some instances (such as "maximize") where no ASH function exists to handle what needs to be done, and this function allows access to such commands from within an ASH script.|
{{Format}}
 
needscode=yes|
 
cli_equiv=The function cli_execute() equivalents you!|
}}

Revision as of 23:37, 10 March 2010

needs(code_samples);

Function Syntax

boolean cli_execute(string command )

  • command is a cli command or commands to execute

This function passes the parameter command on to KoLmafia's CLI, which will execute it as if it were typed in through the normal interface. This function will return true if the CLI command executed properly, and false if it was unable to do so (for example, trying to execute an adventuring command while drunk). Though it's considered a "best practice" to use built-in ASH functions when possible, there are some instances (such as "maximize") where no ASH function exists to handle what needs to be done, and this function allows access to such commands from within an ASH script.

CLI Equivalent

The function cli_execute() equivalents you!