js:MTScript: Difference between revisions
mNo edit summary |
No edit summary |
||
Line 36: | Line 36: | ||
* {{code|pad}} If true, wrap the error in a localized error string. | * {{code|pad}} If true, wrap the error in a localized error string. | ||
* {{code|throws}} AssertFunctionException if {{code|check}} is false. | * {{code|throws}} AssertFunctionException if {{code|check}} is false. | ||
}} | |||
{{MacroFunction | |||
|name=MTScript.setVariable | |||
|trusted=true | |||
|version=1.10.0 | |||
|description= | |||
Sets an MTScript variable. Like {{code|[h: variable = value]}}. For use with {{code|MTScript.evalMacro}}. | |||
|usage= | |||
<source lang="javascript" line> | |||
MTScript.setVariable(variable, value) | |||
</source> | |||
'''Parameters''' | |||
* {{code|variable}} - String, Variable name to set. | |||
* {{code|value}} - Any javascript object. Value to set. | |||
}} | |||
{{MacroFunction | |||
|name=MTScript.getVariable | |||
|trusted=true | |||
|version=1.10.0 | |||
|description= | |||
Reads an MTScript variable. Counterpart to {{code|MTScript.setVariable}}. | |||
|usage= | |||
<source lang="javascript" line> | |||
MTScript.getVariable(variable) | |||
</source> | |||
'''Parameters''' | |||
* {{code|variable}} - String, Variable name to get. | |||
Revision as of 16:17, 5 October 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
Usage
MTScript.abort()
Parameters
throws
- AbortFunctionException
MTScript.mtsAssert;() Function
Note: This function can only be used in a Trusted 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.setVariable() Function
Note: This function can only be used in a Trusted Macro
{{{1}}}
. For use with MTScript.evalMacro
.Usage
MTScript.setVariable(variable, value)
Parameters
variable
- String, Variable name to set.value
- Any javascript object. Value to set.
MTScript.getVariable() Function
Note: This function can only be used in a Trusted Macro
MTScript.setVariable
.Usage
MTScript.getVariable(variable)
Parameters
variable
- String, Variable name to get.
MTScript.evalMacro;() Function
Note: This function can only be used in a Trusted Macro
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
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
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
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
MTScript.registerMacro
.
function yell(str) {
MapTool.chat.broadcast(str.toUpperCase());
}
MTScript.registerMacro("yell", yell);
[h: js.yell("hello world")]
Output:
HELLO WORLD