macro.args: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 5: Line 5:
When a macro on a [[Token:library_token|library token]] is called by another macro, the calling macro may pass one argument to the called macro:
When a macro on a [[Token:library_token|library token]] is called by another macro, the calling macro may pass one argument to the called macro:


<source lang="mtmacro" line>
{| class="wikitable" border="1"
|-
!Calling Macro
!Called Macro
|-
|valign="top"|<source lang="mtmacro" line>
<!-- Call the getDamage macro -->
<!-- Call the getDamage macro -->
[h:damageDice="2d6"]
[MACRO("getDamage@Lib:test"): damageDice]
[MACRO("getDamage@Lib:test"): damageDice]
</source>
</source>
 
|valign="top"|<source lang="mtmacro" line>
In the example above, ''damageDice'' is the argument being passed to the macro '''getDamage''', which resides on the '''Lib:test''' [[Token:library_token|library token]]. Within the '''getDamage''' macro, the variable ''macro.args'' is automatically generated and assigned the value of ''damageDice''.
 
<source lang="mtmacro" line>
<!-- getDamage Macro -->
<!-- getDamage Macro -->
[h:damageRoll = macro.args + 9]
[h:damageRoll = eval(macro.args) + 9]
You hit your target for [r:damageRoll] damage!
You hit your target for [r:damageRoll] damage!
</source>
</source>
|}
In the example above, ''damageDice'' is the argument being passed to the macro '''getDamage''', which resides on the '''Lib:test''' [[Token:library_token|library token]]. Within the '''getDamage''' macro, the variable ''macro.args'' is automatically generated and assigned the value of ''damageDice''.

Revision as of 05:14, 22 December 2008

The variable macro.args holds the value of the argument passed to a trusted macro via the MACRO() roll option. macro.args exists only within the macro that is called, and may be manipulated like any variable in a macro.

Examples

When a macro on a library token is called by another macro, the calling macro may pass one argument to the called macro:

Calling Macro Called Macro
<!-- Call the getDamage macro -->
[h:damageDice="2d6"]
[MACRO("getDamage@Lib:test"): damageDice]
<!-- getDamage Macro -->
[h:damageRoll = eval(macro.args) + 9]
You hit your target for [r:damageRoll] damage!

In the example above, damageDice is the argument being passed to the macro getDamage, which resides on the Lib:test library token. Within the getDamage macro, the variable macro.args is automatically generated and assigned the value of damageDice.