assert: Difference between revisions
Jump to navigation
Jump to search
Bone White (talk | contribs) (Added examples.) |
Bone White (talk | contribs) m (Removed stub tag.) |
||
Line 1: | Line 1: | ||
{{MacroFunction | {{MacroFunction | ||
|name=assert | |name=assert |
Revision as of 16:19, 23 November 2011
assert() Function
• Introduced in version 1.3b49
Halts execution and prints a custom error message if a condition is
false
(0
). Note that the error message will be displayed in chat even if the command itself is in a [H: ] block.Usage
assert(condition, message)
assert(condition, message, prefix)
Parameters
condition
- The test condition that must evaluate totrue
(1
) for the macro to continue.message
- The custom error message that is presented if the macro is halted due to thefalse
(0
) condition.prefix
- Determines if the error message should have the message prefix"Macro defined error: "
. Defaults totrue
(1
), set tofalse
(0
) if you do not wish your custom error message to have the message prefix.
Examples
Checks to see if a player is a GM, and if they are not halts execution of the macro and displays output.
[h: assert(isGM(),"This macro is for GM use only.",0)]
Chat output (if player is not GM): This macro is for GM use only.
Halts execution of the macro if var is a number. This is useful for making sure the variables you work with are the variable type you expect.
[h: assert(! isNumber(var), "The variable is a number.",1)]
Chat output (if var is a number): Macro defined error: The variable is a number.
true
(1
) when var is a number, but assert continues when condition is true
(1
). Using ! isNumber(var)
inverts the boolean value.See Also
Version Changes
- 1.3b51 - Added
prefix
parameter option.