Difference between revisions of "Abort"
Jump to navigation
Jump to search
imported>StDoodle m |
imported>StDoodle |
||
Line 1: | Line 1: | ||
− | {{FunctionPage | | + | {{ |
− | + | #vardefine:name|abort}}{{ | |
+ | #vardefine:return_type|void}}{{ | ||
+ | |||
+ | FunctionPage| | ||
+ | name={{#var:name}}| | ||
function_category=Miscellaneous| | function_category=Miscellaneous| | ||
− | + | ||
− | + | function1={{Function| | |
− | + | name={{#var:name}}| | |
− | + | aggregate={{#var:aggregate}}| | |
+ | return_type={{#var:return_type}}| | ||
+ | return_also={{#var:return_also}}| | ||
+ | }}| | ||
+ | |||
+ | function2={{Function| | ||
+ | name={{#var:name}}| | ||
+ | aggregate={{#var:aggregate}}| | ||
+ | return_type={{#var:return_type}}| | ||
+ | return_also={{#var:return_also}}| | ||
+ | parameter1={{Param|string|message}}| | ||
+ | p1desc={{Pspan|message}} is the (optional) abort message (in place of "KoLmafia declares world peace.")| | ||
+ | }}| | ||
+ | |||
function_description=Halts all queued functions and the entire script it is called from. Often used for error-handling.| | function_description=Halts all queued functions and the entire script it is called from. Often used for error-handling.| | ||
− | code1={{CodeSample | | + | |
− | title=Code | + | code1={{CodeSample| |
+ | title=Code Samples| | ||
description=This code will abort the script if run by the "wrong" character.| | description=This code will abort the script if run by the "wrong" character.| | ||
code= | code= | ||
− | <syntaxhighlight | + | <syntaxhighlight> |
if (my_name() != "MrPicky") { | if (my_name() != "MrPicky") { | ||
abort("I don't want you to run this script, mister!"); | abort("I don't want you to run this script, mister!"); | ||
} | } | ||
− | </syntaxhighlight>}} | | + | </syntaxhighlight>}}| |
− | code2={{CodeSample | | + | |
+ | code2={{CodeSample| | ||
description=An example of '''abort()''' used for error-handling.| | description=An example of '''abort()''' used for error-handling.| | ||
code= | code= | ||
− | <syntaxhighlight | + | <syntaxhighlight> |
float mass = 5.0; | float mass = 5.0; | ||
float volume = some_function(); //where some_function() may return 0.0 | float volume = some_function(); //where some_function() may return 0.0 | ||
Line 31: | Line 50: | ||
cli_equiv=Also available as the CLI command "abort," which will not be queued (similarly stops execution of all remaining commands when parsed). | cli_equiv=Also available as the CLI command "abort," which will not be queued (similarly stops execution of all remaining commands when parsed). | ||
}} | }} | ||
− |
Revision as of 21:36, 8 March 2010
Function Syntax
void abort()
- message is the (optional) abort message (in place of "KoLmafia declares world peace.")
Halts all queued functions and the entire script it is called from. Often used for error-handling.
Code Samples
This code will abort the script if run by the "wrong" character.
if (my_name() != "MrPicky") {
abort("I don't want you to run this script, mister!");
}
An example of abort() used for error-handling.
float mass = 5.0;
float volume = some_function(); //where some_function() may return 0.0
float density;
if (volume_cf == 0) {
abort("Error: Division by zero requested.");
} else {
density = mass / volume;
}
CLI Equivalent
Also available as the CLI command "abort," which will not be queued (similarly stops execution of all remaining commands when parsed).