Macros:Branching and Looping

From RPTools Wiki
Revision as of 16:18, 21 December 2008 by Cclouser (talk | contribs) (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)...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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)

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() block (introduced in Version 1.3.b46)

The second IF() structure allows for the use of CODE execution blocks.

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

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"