Abort vs exit

Grotfang

Developer
Abort vs exit (/return)

So, I'm a big fan of using exit in my scripts when I want them to stop running. Can someone clarify why abort() is so common in its place? What's the difference and why is abort favoured?
 
Last edited:

Spiny

Member
According to kolmafia's wiki:

Code:
exit - logout and exit KoLmafia.

I've never used exit in a script, but I'd assume based on the above that it would do what it says and shut everything down whereas abort just stops the script and allows for a message indicating reason for script abort, but still leaves you logged in to do whatever.
 

Grotfang

Developer
Exit and return in an ASH script do similar things, I believe when used in function main(). Essentially I'm asking why more people don't use return, using abort instead when it probably isn't needed.
 

Veracity

Developer
Staff member
Spiny, exit as an ASH control flow statement is not the same as exit as a CLI command.

In ASH, exit should cleanly unwind all the way out of your script. abort() will also do that, but will set a status message and make the screen go red. To my mind, you should only use abort when your script is stopping execution because of an error.
 

Grotfang

Developer
To my mind, you should only use abort when your script is stopping execution because of an error.

Mine too. It was one moment today that really triggered this thought in my head. I was running That FN Ninja's dwarven factory script (lovely script by the way, bar this minor complaint) and I have already completed the factory quest.

Now... I can see that abort could be useful for stopping the execution of chains of scripts, as well as in case of an error... but I was struggling to see what problem the script was trying to avoid by adding this. Any chaining is going to presuppose access to one or more of the item pieces; which I clearly already have if I have completed the quest this ascension.

I then looked through the other (non-self written) scripts in my directories and noticed that abort as an exit routine was by far the most prolific. I was merely wondering if there was a good reason for this becoming the standard, or if it was due to a lack of knowledge on mafia's return ability for main() - either through
Code:
return;
or through my personal choice of
Code:
exit;

EDIT: What occurred to me as a potential usage (so that chains of scripts would be covered by abort() if needed) would be to set a standard boolean at the top of scripts:

Code:
boolean abort_script = true;

Then, as the control flow statement:

Code:
if(abort_script) abort();
exit;
 
Last edited:
I then looked through the other (non-self written) scripts in my directories and noticed that abort as an exit routine was by far the most prolific. I was merely wondering if there was a good reason for this becoming the standard, or if it was due to a lack of knowledge on mafia's return ability for main()

The latter in my case. I was unaware of the exit command in ash.

I was running That FN Ninja's dwarven factory script (lovely script by the way, bar this minor complaint)

:) Thank you. When I get some time I'll have to adjust my scripts accordingly.
 

zarqon

Well-known member
I tend to prefer abort() (or more recently, ZLib's error()) merely due to the fact that I can specify a message and exit the script, which lets the user know the reason the script quit. Saves me a whole line of code, and often a set of braces!

I'm a bit anal about minimizing my code, I suppose.
 

Catch-22

Active member
To hazard a guess, abort() is probably used because scripters tend to learn a lot by checking out other scripts.

As an example; zarqon has written a lot of popular scripts, so the habit has probably brushed off on people who have learned through zarqon's work.

I'll try to explain the differences between exit and abort() behind the scenes.

abort() will "declare world peace", what this does is set the ABORT_STATE for KoLmafia's continuationState. The continuationState is used by KoLmafia internally, it basically lets KoLmafia know whether or not it should continue to do things (scripts included).

exit will set the InterpreterState to STATE_EXIT for the ASH Interpreter component of KoLmafia ONLY. Unlike abort(), exit does not directly affect the state of KoLmafia's main window.

In my opinion; script writers should only be able to influence the state of the interpreter, not KoLmafia itself. The continuationState should be handled internally by the interpreter and abort() shouldn't even be a part of ASH, but I'm sure a lot of people out there will disagree with me on that one!

:D
 

Bale

Minion
abort is used by most script writers just because it is easy. I try to use it only when there is an error that should abort all adventuring and let the user know he needs to figure things out.
 
Top