macro.return: Difference between revisions
(New page: The variable ''macro.return'' holds the value returned from a called macro to the calling macro. ==Examples== When a macro on a library token is called by another...) |
No edit summary |
||
(10 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
The variable | The variable {{code|macro.return}} holds the value returned from a called macro to the calling macro. Other than {{code|macro.return}}, a called macro shares no other variables with the calling macro. | ||
Additional details on how {{code|macro.return}} interacts with the {{code|ignoreOutput}} parameter of {{func|defineFunction}} can be found on that page. | |||
==Examples== | ==Examples== | ||
When a macro on a [[Token:library_token|library token]] is called by another macro, the called macro may return a value to the called macro by assigning that value to the variable | When a macro on a [[Token:library_token|library token]] is called by another macro, the called macro may return a value to the called macro by assigning that value to the variable {{code|macro.args}}. | ||
===Calling Macro=== | ===Calling Macro=== | ||
The macro below calls a macro called | The macro below calls a macro called {{code|getDamage}} on the [[Token:library_token|library token]] {{code|Lib:combat}}, passing the variable {{code|damageDice}} as an argument. It also sets {{code|returnData}} to the return value of the called macro. | ||
{| class="wikitable" border="1" | {| class="wikitable" border="1" style="border-collapse:collapse;" | ||
|- | |- | ||
!Calling Macro | !Calling Macro | ||
!Called Macro | !Called Macro | ||
|- | |- | ||
|valign="top"|< | |valign="top"|<syntaxhighlight lang="mtmacro" line> | ||
[h:damageDice="2d6"] | |||
[MACRO("getDamage@Lib:combat"):damageDice] | [MACRO("getDamage@Lib:combat"):damageDice] | ||
[h:damageProperties=macro.return] | [h:damageProperties=macro.return] | ||
[h:varsFromStrProp(damageProperties)] | [h:varsFromStrProp(damageProperties)] | ||
</ | </syntaxhighlight> | ||
|< | |<syntaxhighlight lang="mtmacro" line> | ||
<!-- getDamage Macro --> | <!-- getDamage Macro --> | ||
[h:returnData = ""] | [h:returnData = ""] | ||
[h:damageRoll = macro.args + 9] | [h:damageRoll = eval(macro.args) + 9] | ||
[h:damageType = "piercing"] | [h:damageType = "piercing"] | ||
You hit your target for [r:damageRoll] damage! | You hit your target for [r:damageRoll] damage! | ||
Line 28: | Line 31: | ||
[h:returnData=setStrProp(returnData,"damage", damageRoll)] | [h:returnData=setStrProp(returnData,"damage", damageRoll)] | ||
[h:macro.return=returnData] | [h:macro.return=returnData] | ||
</ | </syntaxhighlight> | ||
|} | |} | ||
In the example above, we assume that the | In the example above, we assume that the {{code|getDamage}} macro was called by another macro (for example, a token macro) and has received some value in the form of {{code|macro.args}}. The statements in {{code|getDamage}} are executed, and the final statement assigns the value of {{code|returnData}} to the variable {{code|macro.return}}. | ||
When execution of the | When execution of the {{code|getDamage}} macro is complete and control is handed back to the calling macro, {{code|macro.return}} is also passed back to the calling macro, where it can be manipulated like any other variable. | ||
[[Category:Special Variable]] | |||
[[Category:Macro Function]] |
Latest revision as of 23:59, 4 July 2023
The variable macro.return
holds the value returned from a called macro to the calling macro. Other than macro.return
, a called macro shares no other variables with the calling macro.
Additional details on how macro.return
interacts with the ignoreOutput
parameter of defineFunction() can be found on that page.
Examples
When a macro on a library token is called by another macro, the called macro may return a value to the called macro by assigning that value to the variable macro.args
.
Calling Macro
The macro below calls a macro called getDamage
on the library token Lib:combat
, passing the variable damageDice
as an argument. It also sets returnData
to the return value of the called macro.
Calling Macro | Called Macro |
---|---|
[h:damageDice="2d6"]
[MACRO("getDamage@Lib:combat"):damageDice]
[h:damageProperties=macro.return]
[h:varsFromStrProp(damageProperties)] |
<!-- getDamage Macro -->
[h:returnData = ""]
[h:damageRoll = eval(macro.args) + 9]
[h:damageType = "piercing"]
You hit your target for [r:damageRoll] damage!
[h:returnData=setStrProp(returnData,"damType", damageType)]
[h:returnData=setStrProp(returnData,"damage", damageRoll)]
[h:macro.return=returnData] |
In the example above, we assume that the getDamage
macro was called by another macro (for example, a token macro) and has received some value in the form of macro.args
. The statements in getDamage
are executed, and the final statement assigns the value of returnData
to the variable macro.return
.
When execution of the getDamage
macro is complete and control is handed back to the calling macro, macro.return
is also passed back to the calling macro, where it can be manipulated like any other variable.