js:MTScript: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
mNo edit summary |
||
Line 5: | Line 5: | ||
|name=MTScript.abort | |name=MTScript.abort | ||
|trusted=true | |trusted=true | ||
|version=1. | |version=1.10.0 | ||
|description= | |description= | ||
Similar to the {{func|abort}} macro, but accepts no arguments. Immediately halts macro execution with no message. | Similar to the {{func|abort}} macro, but accepts no arguments. Immediately halts macro execution with no message. | ||
Line 22: | Line 22: | ||
|name=MTScript.mtsAssert; | |name=MTScript.mtsAssert; | ||
|trusted=true | |trusted=true | ||
|version=1. | |version=1.10.0 | ||
|description= | |description= | ||
Like the {{func|assert}} macro. | Like the {{func|assert}} macro. | ||
Line 43: | Line 43: | ||
|name=MTScript.evalMacro; | |name=MTScript.evalMacro; | ||
|trusted=true | |trusted=true | ||
|version=1. | |version=1.10.0 | ||
|description= | |description= | ||
Run a mtscript macro in the current macro context. | Run a mtscript macro in the current macro context. | ||
Line 62: | Line 62: | ||
|name=MTScript.execMacro; | |name=MTScript.execMacro; | ||
|trusted=true | |trusted=true | ||
|version=1. | |version=1.10.0 | ||
|description= | |description= | ||
Run a mtscript macro in <b>a new macro context</b>. This is similar to {{code|evalMacro}}, except variables from the previous macro context are unavailable, and changes to mtscript variables from within this macro are discarded when the macro exits. | Run a mtscript macro in <b>a new macro context</b>. This is similar to {{code|evalMacro}}, except variables from the previous macro context are unavailable, and changes to mtscript variables from within this macro are discarded when the macro exits. | ||
Line 80: | Line 80: | ||
|name=MTScript.getMTScriptCallingArgs; | |name=MTScript.getMTScriptCallingArgs; | ||
|trusted=true | |trusted=true | ||
|version=1. | |version=1.10.0 | ||
|description= | |description= | ||
Returns the arguments passed to {{func|js.eval}} as a list. | Returns the arguments passed to {{func|js.eval}} as a list. |
Revision as of 20:37, 22 September 2021
This article describes a feature or macro function that is experimental and may be subject to change.
Within the javascript environment used by js.eval
, MTScript
is the entry point for interacting with mtscript variables and macros.
MTScript.abort() Function
Note: This function can only be used in a Trusted Macro
• Introduced in version 1.10.0
Similar to the abort() macro, but accepts no arguments. Immediately halts macro execution with no message.
Usage
MTScript.abort()
Parameters
throws
- AbortFunctionException
MTScript.mtsAssert;() Function
Note: This function can only be used in a Trusted Macro
• Introduced in version 1.10.0
Like the assert() macro.
Usage
MTScript.mtsAssert(check, message, pad=true)
Parameters
check
Value to check: iftrue
, do nothing.message
Message to include in the error ifcheck
is false.pad
If true, wrap the error in a localized error string.throws
AssertFunctionException ifcheck
is false.
MTScript.evalMacro;() Function
Note: This function can only be used in a Trusted Macro
• Introduced in version 1.10.0
Run a mtscript macro in the current macro context.
Usage
MTScript.evalMacro(macro)
Parameters
macro
String to run as a macro.return
Any mtscript type.
MTScript.execMacro;() Function
Note: This function can only be used in a Trusted Macro
• Introduced in version 1.10.0
Run a mtscript macro in a new macro context. This is similar to
evalMacro
, except variables from the previous macro context are unavailable, and changes to mtscript variables from within this macro are discarded when the macro exits.Usage
MTScript.execMacro(macro)
Parameters
macro
String to run as a macro.return
Any mtscript type.
MTScript.getMTScriptCallingArgs;() Function
Note: This function can only be used in a Trusted Macro
• Introduced in version 1.10.0
Returns the arguments passed to js.eval() as a list.
Usage
MTScript.getMTScriptCallingArgs()
Parameters
return
list of arguments passed to the current js.eval() call.
MTScript.registerMacro;() Function
Note: This function can only be used in a Trusted Macro
• Introduced in version 1.10.0
Registers a javascript function as a MT UDF under the js. prefix.
Usage
MTScript.registerMacro(macroName, callable)
Parameters
macroName
Name for the new UDF. Note that "js." will be prepended to the name.callable
Any javascript callable.
Example
Using
MTScript.registerMacro
.
function yell(str) {
MapTool.chat.broadcast(str.toUpperCase());
}
MTScript.registerMacro("yell", yell);
[h: js.yell("hello world")]
Output:
HELLO WORLD