defineFunction: Difference between revisions
m (Text replacement - "<source" to "<syntaxhighlight") |
m (Text replacement - "source>" to "syntaxhighlight>") |
||
Line 10: | Line 10: | ||
<syntaxhighlight lang="mtmacro" line> | <syntaxhighlight lang="mtmacro" line> | ||
defineFunction(function, macro) | defineFunction(function, macro) | ||
</ | </syntaxhighlight> | ||
<syntaxhighlight lang="mtmacro" line> | <syntaxhighlight lang="mtmacro" line> | ||
defineFunction(function, macro, ignoreOutput) | defineFunction(function, macro, ignoreOutput) | ||
</ | </syntaxhighlight> | ||
<syntaxhighlight lang="mtmacro" line> | <syntaxhighlight lang="mtmacro" line> | ||
defineFunction(function, macro, ignoreOutput, newScope) | defineFunction(function, macro, ignoreOutput, newScope) | ||
</ | </syntaxhighlight> | ||
'''Parameters''' | '''Parameters''' | ||
{{param|function|The name of the user defined function to be defined. }} | {{param|function|The name of the user defined function to be defined. }} | ||
Line 36: | Line 36: | ||
<syntaxhighlight lang="mtmacro" line> | <syntaxhighlight lang="mtmacro" line> | ||
[h: defineFunction("character.heal", "heal@Lib:Character")] | [h: defineFunction("character.heal", "heal@Lib:Character")] | ||
</ | </syntaxhighlight> | ||
Defines a function {{code|character.heal()}} which calls {{code|heal@Lib:Character}} when evoked. Note that in this case there must exist a function called "heal" on a token called "lib:Character". The advantage of using the prefix "lib:" on the token name is that it becomes a "lib:token" which is accessible from ANY map instead of only the map you happen to have active. | Defines a function {{code|character.heal()}} which calls {{code|heal@Lib:Character}} when evoked. Note that in this case there must exist a function called "heal" on a token called "lib:Character". The advantage of using the prefix "lib:" on the token name is that it becomes a "lib:token" which is accessible from ANY map instead of only the map you happen to have active. | ||
Line 43: | Line 43: | ||
<syntaxhighlight lang="mtmacro" line> | <syntaxhighlight lang="mtmacro" line> | ||
[h: character.heal("hello", "hi")] | [h: character.heal("hello", "hi")] | ||
</ | </syntaxhighlight> | ||
then these parameters can be accessed inside {{code|character.heal()}} by using | then these parameters can be accessed inside {{code|character.heal()}} by using | ||
<syntaxhighlight lang="mtmacro" line> | <syntaxhighlight lang="mtmacro" line> | ||
[h: firstArg = arg(0)] | [h: firstArg = arg(0)] | ||
[h: theOtherOne = arg(1)] | [h: theOtherOne = arg(1)] | ||
</ | </syntaxhighlight> | ||
|also= | |also= |
Revision as of 18:38, 14 March 2023
This article is a stub, you can help the RPTools Wiki project by contributing content to expand this article.
This article needs: Could use examples of the ignoreOutput and newScope parameters.
defineFunction() Function
Note: This function can only be used in a Trusted Macro
Usage
defineFunction(function, macro)
defineFunction(function, macro, ignoreOutput)
defineFunction(function, macro, ignoreOutput, newScope)
Parameters
function
- The name of the user defined function to be defined.macro
- The name and location of the macro that is called when the user defined function is used.ignoreOutput
- If the defined function should ignore all output and only return the value ofmacro.return
, defaults tofalse
(0
).newScope
- If the defined function should create a new variable scope when executed, defaults totrue
(1
). A new variable scope means that the defined function can only read the variables of the macro that called it; if you do not create a new scope the defined function can read, update, and create variables in its parent's variable scope. Updating variables in the parent's scope includes over-writing any parameters that a parent might have stored within arg(), if a user-defined function that does not create a new scope is called within another user-defined function.
Interactions between the ignoreOutput
parameter and the macro.return special variable:
- If the UDF sets the value of macro.return and
ignoreOutput
is0
then any output is the return value and macro.return has the value assigned.
- If the UDF sets the value of macro.return and
ignoreOutput
is1
then the return value is the value assigned to macro.return and macro.return has the value assigned.
- If the UDF has output to chat, macro.return is not set and
ignoreOutput
is0
then that output is the return value and macro.return is empty.
- If the UDF has output to chat, macro.return is not set and
ignoreOutput
is1
then the return value and macro.return are empty.
Example
[h: defineFunction("character.heal", "heal@Lib:Character")]
Defines a function character.heal()
which calls heal@Lib:Character
when evoked. Note that in this case there must exist a function called "heal" on a token called "lib:Character". The advantage of using the prefix "lib:" on the token name is that it becomes a "lib:token" which is accessible from ANY map instead of only the map you happen to have active.
Should you pass on any arguments e.g.
[h: character.heal("hello", "hi")]
then these parameters can be accessed inside character.heal()
by using
[h: firstArg = arg(0)]
[h: theOtherOne = arg(1)]
See Also
Version Changes
- 1.3b56 - Added
ignoreOutput
andnewScope
parameter options.