abort: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
{{ | {{stub}} | ||
{{Languages|abort}} | {{Languages|abort}} | ||
{{MacroFunction | {{MacroFunction |
Revision as of 22:44, 9 February 2023
This article is a stub, you can help the RPTools Wiki project by contributing content to expand this article.
abort() Function
abort()
is 0 then the execution of the macro stops and all macro output is discarded. If the argument to abort()
is non zero then the macro continues.
Note that only the output of the macro is discarded when the macro is aborted any changes made to macros will not be undone.
Common uses for this function are
- Ending a macro if the cancel button is clicked on an input dialog created using the input() function.
- Discarding all output generated by the macro, in effect making a "silent" macro.
- Silently bailing out of a macro if a certain condition is not met.
assert()
function.Usage
abort(abrt)
Parameters
abrt
-0
if the abort function should abort the macro, nonzero if it should not.
Examples
[h: res = input("blah")] [h: abort(res)]
The following example discards any output in the macro.
Hah! you will never see this! [abort(0)]
The following line can be used to protect macros that only the GM should run
[h: abort(isGM())]
The following line can be used to silently end a macro that can only be run from a Trusted Macro
[h: abort(isTrusted())]
Usage Notes
When aborting a macro called from another macro (for example, a library token), all macros are aborted, not just the one executing.
Since 1.5.0 you can change that behaviour by using macro.catchAbort.
Calling Macro
<!-- Call the getAmmo library macro -->
[MACRO("getAmmo@Lib:test"): "arrows"]
You have [r:macro.return] arrows.
Called Macro
<!-- getAmmo macro in Lib:test token -->
[h: macro.return = 0]
[h: abort(json.contains(ammunition, macro.args))]
[h: macro.return = json.get(ammunition, macro.args)]
Results
assuming ammunition = { "arrows" : 30 }
TokenName: You have 30 arrows.
assuming ammunition = { "bolts" : 20 }
(nothing)See Also
Version Changes
- 1.3b49 - No message is displayed if called from a macroLink.
- 1.5.0 - catch an abort with macro.catchAbort