RPTools

From MapToolDoc

code (roll option)

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

Contents

CODE

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.

Usage

  1. [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.

Example

  1. [h:num=5]
  2. [WHILE(num > 0), CODE:
  3. {
  4.   This is iteration [r:num] <br>
  5.   There are [r:num-1] iterations left<br>
  6.   [num=num-1]
  7. }]

Outputs

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
0

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:

  1. [h:d20roll=1d20]
  2. [h:attackRoll=d20roll+AttackBonus]
  3. [h,IF(attackRoll >= 16),CODE:
  4. {
  5.   [IF(d20roll == 20),CODE:
  6.   {
  7.     The attack is a critical hit!
  8.     [h:damage=critDamage]
  9.   };
  10.   {
  11.     The attack is a hit!
  12.     [h:damage=regDamage]
  13.   };]
  14. };
  15. {
  16.   The attack misses!
  17. };]

MapTool can only handle two levels of nested code.