code (roll option)

From RPTools Wiki
Jump to navigation Jump to search

 This article is a stub, you can help the RPTools Wiki project by contributing content to expand this article.


Introduced: Version 1.3.b46

The CODE option is used in conjunction with looping / branching options to execute multiple statements within a single "block" of a loop or branch, allowing the creation of more complex loops and branches.


[CODE: { code_block }]

The code_block is a collection of text and macro code, enclosed in a single {} pair. Everything within the {} is treated as a single block for the purposes of any looping or branching options.


[WHILE(num > 0), CODE:
  This is iteration [r:num] <br>
  There are [r:num-1] iterations left<br>


This is iteration 5 There are 4 iterations left
4, This is iteration 4 There are 3 iterations left
3, This is iteration 3 There are 2 iterations left
2, This is iteration 2 There are 1 iterations left
1, This is iteration 1 There are 0 iterations left

NOTE: the digit output at the beginning of each line is an artifact of the WHILE loop's evaluation of num - since this roll does not have the h option active, the result of that evaluation is displayed.

Nested CODE Blocks

To nest CODE:{} blocks, use a second CODE:{ } option, like so:

[h,IF(attackRoll >= 16),CODE:
  [IF(d20roll == 20),CODE:
    The attack is a critical hit!
    The attack is a hit!
  The attack misses!

MapTool can only handle two levels of nested code.