RPTools

From MapToolDoc

switch (roll option)

Contents

[switch():] Roll Option

* Introduced in version 1.3b46

Chooses among several options and executes code based on the expression.

Usage

  1. [switch(expression):
  2.    case case1: body1;
  3.    case case2: body2;
  4.    default: defaultBody
  5. ]

Parameters

  • expression - The regular expression that determines which case is executed. Since this is a regular expression, metacharacters such as * and () will need to have backslashes in front of them if you want to match them literally.
  • case - A potential match for the expression, possesses a corresponding body that is executed if a match is made.
  • default - If the expression finds no matches within the cases, then the defaultBody is executed.

Examples

  1. [h:powerType="at-will"]
  2. [switch(powerType):
  3. case "at-will": "You may use this power as much as you like";
  4. case "encounter": "You may only use this power once per encounter";
  5. case "daily": "You may only use this power once per day"]

Outputs You may use this power as much as you like

  1. [h:powerType=".*sword.*"]
  2. [switch(powerType):
  3. case "flail": "one-handed weapon; two-handed does Str*2 damage";
  4. case "shortsword": "used for jabs, so is a puncturing weapon";
  5. case "longsword": "a slashing weapon"]

Outputs used for jabs, so is a puncturing weapon. Notice that the first matching clause was the one that the [switch():] option found.

When using the [code():] option with a switch option, each case body its own set of braces, like so:

  1. [h,switch(class),code:
  2. case "Warrior": {
  3.   [Armor = 6]
  4.   [beginningPowers = "Sword, Shield Bash, Bow, Shield, Torch"]
  5. };
  6. case "Rogue": {
  7.   [Armor = 2]
  8.   [beginningPowers = "Dagger, Hide, Backstab, Pick Lock, Torch"]
  9. };
  10. case "Wizard": {
  11.   [Armor = 1]
  12.   [beginningPowers = "Dagger, Staff, Light, Lightning Bolt, Fire Ball"]
  13. };
  14. case "Priest": {
  15.   [Armor = 4]
  16.   [beginningPowers = "Mace, Heal, Protect, Banish Undead, Torch"]
  17. };
  18. default: {
  19.   [Armor = 0]
  20.   [beginningPowers = "Fists, Feet"]
  21. }]

See Also

if(), [if():], Introduction to Macro Branching