switch (roll option): Difference between revisions
Jump to navigation
Jump to search
Verisimilar (talk | contribs) (Redirect pending split of article.) |
Verisimilar (talk | contribs) m (Initial copy-over.) |
||
Line 1: | Line 1: | ||
{{RollOption | |||
[[ | |name=switch | ||
|version=1.3b46 | |||
|description= | |||
Chooses among several options and executes code based on the expression. | |||
|usage= | |||
<source lang="mtmacro" line> | |||
[switch(expression): | |||
case case1: body1; | |||
case case2: body2; | |||
default: defaultBody | |||
] | |||
</source> | |||
'''Parameters''' | |||
{{param|expression|The ''regular expression'' that determines which case is executed. Since this is a ''regular expression'', metacharacters such as {{code|*}} and {{code|()}} will need to have backslashes in front of them if you want to match them literally.}} | |||
{{param|case|A potential match for the {{code|expression}}, possesses a corresponding {{code|body}} that is executed if a match is made.}} | |||
{{param|default|If the {{code|expression}} finds no matches within the {{code|case}}s, then the {{code|defaultBody}} is executed.}} | |||
|examples= | |||
<source lang="mtmacro" line> | |||
[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"] | |||
</source> | |||
Outputs {{code|You may use this power as much as you like}} | |||
<source lang="mtmacro" line> | |||
[h:powerType=".*sword.*"] | |||
[SWITCH(powerType): | |||
case "flail": "one-handed weapon; two-handed does Str*2 damage"; | |||
case "shortsword": "used for jabs, so is a puncturing weapon"; | |||
case "longsword": "a slashing weapon"] | |||
</source> | |||
Outputs {{code|used for jabs, so is a puncturing weapon}}. Notice that the first matching clause was the one that the SWITCH() option found. | |||
}} | |||
[[Category:Branching Roll Option]] | [[Category:Branching Roll Option]] |
Revision as of 03:20, 5 April 2009
[switch():] Roll Option
* Introduced in version 1.3b46
Chooses among several options and executes code based on the expression.
Usage
[switch(expression):
case case1: body1;
case case2: body2;
default: defaultBody
]
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 theexpression
, possesses a correspondingbody
that is executed if a match is made.default
- If theexpression
finds no matches within thecase
s, then thedefaultBody
is executed.
Examples
[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"]
Outputs You may use this power as much as you like
[h:powerType=".*sword.*"]
[SWITCH(powerType):
case "flail": "one-handed weapon; two-handed does Str*2 damage";
case "shortsword": "used for jabs, so is a puncturing weapon";
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.