Difference between revisions of "Tips, Tricks and Workarounds"

From Kolmafia
Jump to navigation Jump to search
imported>Bale
imported>Bale
Line 12: Line 12:
  
 
== Capturing an Abort ==
 
== Capturing an Abort ==
 +
 +
By default, whenever an ASH function returns false, everything will abort ''unless'' you somehow capture the return value (i.e. assigning it to a variable or enclosing it in a control structure). So, if you want to make use of, say, the hermit() function in a way that won't abort if the function returns false, you could:
 +
<div style="margin-bottom: 1em; padding: 1em; margin:0px 20px;">
 +
{{CodeSample|
 +
description=Save the result as a boolean variable.|
 +
code=<syntaxhighlight>
 +
boolean fakeBool = hermit(1, $item[Ten-leaf clover]);
 +
</syntaxhighlight>}}
 +
{{CodeSample|
 +
description=Capture the result in an if() conditional.|
 +
code=<syntaxhighlight>
 +
if(!hermit(1, $item[Ten-leaf clover])) print("Hermit looting failed: continuing on.");
 +
</syntaxhighlight>}}
 +
{{CodeSample|
 +
description=An if() conditional doesn't even have to do anything.|
 +
code=<syntaxhighlight>
 +
if(hermit(1, $item[Ten-leaf clover])) {}
 +
</syntaxhighlight>}}
 +
{{CodeSample|
 +
description=The most minimalistic method is to capture it with a not operator and parenthesis.|
 +
code=<syntaxhighlight>
 +
(!hermit(1, $item[Ten-leaf clover]));
 +
</syntaxhighlight>}}
 +
</div>
 +
 +
Any of these will capture the return value and prevent mafia from aborting.
  
 
== Syntax Highlighting for Notepad++ ==
 
== Syntax Highlighting for Notepad++ ==
  
 
[[Category:Scripting]]
 
[[Category:Scripting]]

Revision as of 06:22, 25 September 2010

Free Pulls

KoLmafia considers free pulls as completely separate from other items in Hangks. Because there is no resource being consumed by pulling them, they do not use the functions involved in pulls, specifically storage_amount() and take_storage().

To find the quantity of a free pull in Hangks, such as a brick you need to use available_amount(). To remove a free pull item from Hangks you need to use retrieve_item().

Anonymous closures

print()

Capturing an Abort

By default, whenever an ASH function returns false, everything will abort unless you somehow capture the return value (i.e. assigning it to a variable or enclosing it in a control structure). So, if you want to make use of, say, the hermit() function in a way that won't abort if the function returns false, you could:

Save the result as a boolean variable.

boolean fakeBool = hermit(1, $item[Ten-leaf clover]);

Capture the result in an if() conditional.

if(!hermit(1, $item[Ten-leaf clover])) print("Hermit looting failed: continuing on.");

An if() conditional doesn't even have to do anything.

if(hermit(1, $item[Ten-leaf clover])) {}

The most minimalistic method is to capture it with a not operator and parenthesis.

(!hermit(1, $item[Ten-leaf clover]));

Any of these will capture the return value and prevent mafia from aborting.

Syntax Highlighting for Notepad++