What functions are treated as assertions?

philmasterplus

Active member
I recently learned that some built-in ASH functions behave like assertions when their return values are not used:
Code:
// Abort the script if it fails to retrieve the item
retrieve_item(1, $item[ mae west ]);
// Don't abort the script even if it fails to retrieve the item
boolean result = retrieve_item(1, $item[ mae west ]);

I skimmed RuntimeLibrary.java and updated the wiki page with a list of functions that return continueValue(). Is this list correct, or are there any other functions that behave like assertions?
 

heeheehee

Developer
Staff member
As I mentioned, this is relevant to anything and everything that puts Mafia into an error state, library function or user-defined.

For instance (just to cherrypick an example that isn't in your list):
Code:
item CCW = $item[counterclockwise watch];
boolean wrapper() {
  int ignored = craft("combine", 1, CCW, CCW);
  print("this is printed");

  craft("combine", 1, CCW, CCW);
  print("this isn't printed");

  return true;
}

boolean also_ignored = wrapper();
print("also this is printed");
wrapper();
print("while this is not");

edit with gCLI output:
Code:
 > call test.ash
Searching for "Counterclockwise Watch"...
Search complete.
Desired purchase quantity not reached (wanted 1, got 0)
Searching for "Counterclockwise Watch"...
Search complete.
Desired purchase quantity not reached (wanted 1, got 0)
You need 1 more Counterclockwise Watch to continue.
this is printed
Searching for "Counterclockwise Watch"...
Search complete.
Desired purchase quantity not reached (wanted 1, got 0)
Searching for "Counterclockwise Watch"...
Search complete.
Desired purchase quantity not reached (wanted 1, got 0)
You need 1 more Counterclockwise Watch to continue.
Stack trace:

also this is printed
Searching for "Counterclockwise Watch"...
Search complete.
Desired purchase quantity not reached (wanted 1, got 0)
Searching for "Counterclockwise Watch"...
Search complete.
Desired purchase quantity not reached (wanted 1, got 0)
You need 1 more Counterclockwise Watch to continue.
this is printed
Searching for "Counterclockwise Watch"...
Search complete.
Desired purchase quantity not reached (wanted 1, got 0)
Searching for "Counterclockwise Watch"...
Search complete.
Desired purchase quantity not reached (wanted 1, got 0)
You need 1 more Counterclockwise Watch to continue.
Stack trace:
 

philmasterplus

Active member
That sounds tricky to describe without knowledge of KoLmafia's internal mechanics.

Suppose I want to prevent my code from aborting. Is there a rule of thumb that I can use to decide which functions to capture?
 
Top