Macros:Branching and Looping: Difference between revisions
(New page: This page details the branching and looping structures in MapTool. ==Branching== ===IF=== There are two IF structures in MapTool. ===="Excel-style" if() (introduced in Version 1.3.b38)...) |
No edit summary |
||
Line 3: | Line 3: | ||
==Branching== | ==Branching== | ||
===IF | ===Block IF()=== | ||
;Usage | ;Usage | ||
Line 22: | Line 18: | ||
Returns ''Value is greater''. | Returns ''Value is greater''. | ||
===IF Option (introduced in Version 1.3.b46)=== | |||
The second IF() structure | The second IF() structure is a roll option, placed inside square brackets ''prior'' to the colon, as with other [[Macros:Roll:types | roll options]]. | ||
;Usage | ;Usage | ||
Line 46: | Line 42: | ||
Displays ''New Value = 144''. | Displays ''New Value = 144''. | ||
===SWITCH=== | ===SWITCH Option=== | ||
SWITCH chooses among several options and executes code based on the switch expression. | SWITCH chooses among several options and executes code based on the switch expression. | ||
Line 70: | Line 66: | ||
Displays "You may use this power as much as you like" | Displays "You may use this power as much as you like" | ||
==Looping== | |||
===COUNT Option=== | |||
The COUNT option executes a statement a specified number of times, storing the number of the current iteration in a variable called ''roll.count''. | |||
====Usage==== | |||
<source lang="mtmacro" line> | |||
[COUNT(num): body] | |||
[COUNT(num, separator): body] | |||
</source> | |||
The ''roll.count'' variable will take on values from 0 to (number of loops - 1). The optional separator (default ", ") is printed between each iteration. | |||
====Example==== | |||
<source lang="mtmacro" line> | |||
[h:numHits=3] | |||
[COUNT(numHits): Damage = Damage + 1d12] | |||
</source> | |||
Will iterate the ''Damage = Damage + 1d12'' operation 3 times. |
Revision as of 16:28, 21 December 2008
This page details the branching and looping structures in MapTool.
Branching
Block IF()
- Usage
[h: if(condition, true_value, false_value)]
- Example
[h: val=12]
[h: if(val > 10, "Value is greater", "Value is less")]
Returns Value is greater.
IF Option (introduced in Version 1.3.b46)
The second IF() structure is a roll option, placed inside square brackets prior to the colon, as with other roll options.
- Usage
[IF(condition): true_body; false_body]
or
[IF(condition): true_body]
Either the true_body or false_body will be used, depending on the value of condition. If the false_body is not given but the condition is false, then there is no output.
- Example
[h:val=12]
[IF(val == 12): newVal=12*12]
New Value = [r:newVal]
Displays New Value = 144.
SWITCH Option
SWITCH chooses among several options and executes code based on the switch expression.
Usage
[SWITCH(expression):
case case1: body1;
case case2: body2;
default: default_body]
Example
[h:powerType="at-will"]
[SWITCH(powerType):
case "at-will": "You may use this power as much as you like";
case "encounter": "You may only use this power once per encounter";
case "daily": "You may only use this power once per day"]
Displays "You may use this power as much as you like"
Looping
COUNT Option
The COUNT option executes a statement a specified number of times, storing the number of the current iteration in a variable called roll.count.
Usage
[COUNT(num): body]
[COUNT(num, separator): body]
The roll.count variable will take on values from 0 to (number of loops - 1). The optional separator (default ", ") is printed between each iteration.
Example
[h:numHits=3]
[COUNT(numHits): Damage = Damage + 1d12]
Will iterate the Damage = Damage + 1d12 operation 3 times.