Cli execute: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>Eliteofdelete
No edit summary
Convert to Template:Function2 format, modernize code example
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{
<onlyinclude>{{{{{format|Function2}}}
#vardefine:name|cli_execute}}{{
|name=cli_execute
#vardefine:return_type|boolean}}{{
|function1.return_type=boolean
|function1.description=Executes a string as a gCLI command. Returns <code>true</code> on success, <code>false</code> on failure.
|function1.param1=command
|function1.param1.type=string
|function1.param1.description=gCLI command(s) to execute
|description=<p>This function passes the parameter {{pspan|command}} to KoLmafia's gCLI, which will execute it as though it was typed in through the normal interface. This function will return <code>true</code> if the gCLI command executed properly, and <code>false</code> if it was unable to do so (for example, trying to execute an adventuring command while drunk).</p>


FunctionPage|
<p>Though it is considered a "best practice" to use built-in ASH functions whenever possible, there are some cases where no ASH function exists to handle a task (e.g. creating moods). This function provides an escape hatch for such tasks by using gCLI commands from within an ASH script.</p>
name={{#var:name}}|


function1={{Function|
<p>{{f|cli_execute}} is used most commonly for functions that do not have an ASH equivalent. More CLI commands can be found at the [[CLI Reference]], or by typing "help" into the gCLI window.</p>
name={{#var:name}}|
|code1={{CodeSample
aggregate={{#var:aggregate}}|
  |title=Code Samples
return_type={{#var:return_type}}|
  |description=This example maximizes your meat drop percentage and spends all of your adventures in {{kolwiki|The Castle in the Clouds in the Sky (Top Floor)}}.
return_also={{#var:return_also}}|
  |code=
parameter1={{Param|string|command}}|
<syntaxhighlight lang="d">
p1desc={{Pspan|command}} is a cli command or commands to execute|
cli_execute( "maximize meat, switch hobo monkey, -switch leprechaun" );
}}|
adventure( my_adventures(), $location[ The Castle in the Clouds in the Sky (Top Floor) ] );
 
</syntaxhighlight>
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.|
  |moreinfo=
 
}}
code1={{CodeSample|
|code2={{CodeSample
title=Code Samples|
  |description=A basic leveling mood setup using CLI Execute as ASH does not have anything similar.
description=This example maximizes your meat drop percentage and spends all of your adventures in the Castle|
  |code=
code=
<syntaxhighlight lang="d">
<syntaxhighlight>
// Mood Name
cli_execute("maximize meat, switch hobo monkey, -switch leprechaun");
cli_execute( "mood MoxieLeveling" );
adventure( my_adventures(), $location[Giant's Castle] );
cli_execute( "mood clear" );
</syntaxhighlight>}}|
// Remove Poisons
 
cli_execute( "trigger gain_effect, somewhat poisoned, uneffect Somewhat Poisoned" );
code2={{CodeSample|
cli_execute( "trigger gain_effect, Hardly Poisoned at All, uneffect Hardly Poisoned at All" );
description=<br>A basic leveling mood setup using CLI Execute as ASH does not have anything similar.|
cli_execute( "trigger gain_effect, A Little Bit Poisoned, uneffect A Little Bit Poisoned" );
code=
cli_execute( "trigger gain_effect, Really Quite Poisoned, uneffect Really Quite Poisoned" );
<syntaxhighlight>
cli_execute( "trigger gain_effect, Majorly Poisoned, uneffect Majorly Poisoned" );
//Mood Name
cli_execute( "trigger gain_effect, Toad In The Hole, uneffect Toad In The Hole" );
cli_execute("mood MoxieLeveing");
cli_execute( "trigger gain_effect, just the best anapests, uneffect just the best anapests" );
cli_execute("mood clear");
// Store Buffs
//Remove Poisons
if ( my_meat() >= 500 )
cli_execute("trigger gain_effect, somewhat poisoned, uneffect Somewhat Poisoned");
   cli_execute( "trigger lose_effect, Butt-Rock Hair, use 10 hair spray" );
cli_execute("trigger gain_effect, Hardly Poisoned at All, uneffect Hardly Poisoned at All");
// Smiles
cli_execute("trigger gain_effect, A Little Bit Poisoned, uneffect A Little Bit Poisoned");
if ( have_skill( $skill[ Knowing Smile ] ) && my_maxmp() >= 20 )
cli_execute("trigger gain_effect, Really Quite Poisoned, uneffect Really Quite Poisoned");
   cli_execute( "trigger lose_effect, Knowing Smile, cast 1 Knowing Smile" );
cli_execute("trigger gain_effect, Majorly Poisoned, uneffect Majorly Poisoned");
else if ( have_skill( $skill[ disco smirk ] ) && my_maxmp() >= 20 )
cli_execute("trigger gain_effect, Toad In The Hole, uneffect Toad In The Hole");
   cli_execute( "trigger lose_effect, Disco Smirk, cast 1 Disco Smirk" );
cli_execute("trigger gain_effect, just the best anapests, uneffect just the best anapests");
// DB Skills
//Store Buffs
if ( have_skill( $skill[ Disco Aerobics ] ) )
if (my_meat() >= 500)
   cli_execute( "trigger lose_effect, Disco State of Mind, cast 5 Disco Aerobics" );
   cli_execute("trigger lose_effect, Butt-Rock Hair, use 10 hair spray");
// AT Skills
//Smiles
if ( have_skill( $skill[ Moxie of the Mariachi ] ) )
if (have_skill($skill[Knowing Smile]) && my_maxmp() >= 20)  
   cli_execute( "trigger lose_effect, Mariachi Mood, cast 5 Moxie of the Mariachi" );
   cli_execute("trigger lose_effect, Knowing Smile, cast 1 Knowing Smile");
// Songs
else if (have_skill($skill[disco smirk]) && my_maxmp() >= 20)
if ( have_skill( $skill[ The Moxious Madrigal ] ) && my_maxmp() >= 2 )
   cli_execute("trigger lose_effect, Disco Smirk, cast 1 Disco Smirk");
   cli_execute( "trigger lose_effect, The Moxious Madrigal, cast 1 The Moxious Madrigal" );
//DB Skills
// Execute the mood
if (have_skill($skill[Disco Aerobics]))
mood_execute(1);
   cli_execute("trigger lose_effect, Disco State of Mind, cast 5 Disco Aerobics");
</syntaxhighlight>
//At Skills
  |moreinfo=
if (have_skill($skill[Moxie of the Mariachi]))
   cli_execute("trigger lose_effect, Mariachi Mood, cast 5 Moxie of the Mariachi");
//Songs  
if (have_skill($skill[The Moxious Madrigal]) && my_maxmp() >= 2)
   cli_execute("trigger lose_effect, The Moxious Madrigal, cast 1 The Moxious Madrigal");
//Execute the mood
cli_execute("mood execute");
</syntaxhighlight>|
moreinfo=
Cli_execute is used most commonly for functions that do not have an ASH equivalent like the above two examples. More CLI commands can be found here (http://wiki.kolmafia.us/index.php?title=CLI_Reference) or typing "help" into the CLI window.
}}|
 
cli_equiv=The function cli_execute() equivalents you!|
}}
}}
 
|see_also={{SeeAlso/gCLI Functions}}
|cli_equiv=The function cli_execute() equivalents you!
|more_info=
|special=
|{{{1|}}}
}}</onlyinclude>
[[Category:Miscellaneous Functions]]
[[Category:Miscellaneous Functions]]

Latest revision as of 14:41, 23 December 2020

Function Syntax

boolean cli_executestring command )

Executes a string as a gCLI command. Returns true on success, false on failure.
  • command: gCLI command(s) to execute

This function passes the parameter command to KoLmafia's gCLI, which will execute it as though it was typed in through the normal interface. This function will return true if the gCLI command executed properly, and false if it was unable to do so (for example, trying to execute an adventuring command while drunk).

Though it is considered a "best practice" to use built-in ASH functions whenever possible, there are some cases where no ASH function exists to handle a task (e.g. creating moods). This function provides an escape hatch for such tasks by using gCLI commands from within an ASH script.

cli_execute() is used most commonly for functions that do not have an ASH equivalent. More CLI commands can be found at the CLI Reference, or by typing "help" into the gCLI window.

Code Samples

This example maximizes your meat drop percentage and spends all of your adventures in The Castle in the Clouds in the Sky (Top Floor).

cli_execute( "maximize meat, switch hobo monkey, -switch leprechaun" );
adventure( my_adventures(), $location[ The Castle in the Clouds in the Sky (Top Floor) ] );

A basic leveling mood setup using CLI Execute as ASH does not have anything similar.

// Mood Name
cli_execute( "mood MoxieLeveling" );
cli_execute( "mood clear" );
// Remove Poisons
cli_execute( "trigger gain_effect, somewhat poisoned, uneffect Somewhat Poisoned" );
cli_execute( "trigger gain_effect, Hardly Poisoned at All, uneffect Hardly Poisoned at All" );
cli_execute( "trigger gain_effect, A Little Bit Poisoned, uneffect A Little Bit Poisoned" );
cli_execute( "trigger gain_effect, Really Quite Poisoned, uneffect Really Quite Poisoned" );
cli_execute( "trigger gain_effect, Majorly Poisoned, uneffect Majorly Poisoned" );
cli_execute( "trigger gain_effect, Toad In The Hole, uneffect Toad In The Hole" );
cli_execute( "trigger gain_effect, just the best anapests, uneffect just the best anapests" );
// Store Buffs
if ( my_meat() >= 500 )
   cli_execute( "trigger lose_effect, Butt-Rock Hair, use 10 hair spray" );
// Smiles
if ( have_skill( $skill[ Knowing Smile ] ) && my_maxmp() >= 20 )
   cli_execute( "trigger lose_effect, Knowing Smile, cast 1 Knowing Smile" );
else if ( have_skill( $skill[ disco smirk ] ) && my_maxmp() >= 20 )
   cli_execute( "trigger lose_effect, Disco Smirk, cast 1 Disco Smirk" );
// DB Skills
if ( have_skill( $skill[ Disco Aerobics ] ) )
   cli_execute( "trigger lose_effect, Disco State of Mind, cast 5 Disco Aerobics" );
// AT Skills
if ( have_skill( $skill[ Moxie of the Mariachi ] ) )
   cli_execute( "trigger lose_effect, Mariachi Mood, cast 5 Moxie of the Mariachi" );
// Songs
if ( have_skill( $skill[ The Moxious Madrigal ] ) && my_maxmp() >= 2 )
   cli_execute( "trigger lose_effect, The Moxious Madrigal, cast 1 The Moxious Madrigal" );
// Execute the mood
mood_execute(1);

CLI Equivalent

The function cli_execute() equivalents you!

See Also

cli_execute() | cli_execute_output()