getStrProp: Difference between revisions
m (Conversion script moved page GetStrProp to getStrProp: Converting page titles to lowercase) |
m (Text replacement - "source>" to "syntaxhighlight>") |
||
Line 10: | Line 10: | ||
getStrProp(propList, key, default) | getStrProp(propList, key, default) | ||
getStrProp(propList, key, default, delim) | getStrProp(propList, key, default, delim) | ||
</ | </syntaxhighlight> | ||
'''Parameters''' | '''Parameters''' | ||
{{param|proplist|String property list to extract data from.}} | {{param|proplist|String property list to extract data from.}} | ||
Line 22: | Line 22: | ||
[h: weapon = "name=longsword; damage=1d8; maxdamage=8"] | [h: weapon = "name=longsword; damage=1d8; maxdamage=8"] | ||
Name of Weapon: [r: getStrProp(weapon, "name")] | Name of Weapon: [r: getStrProp(weapon, "name")] | ||
</ | </syntaxhighlight> | ||
Returns {{code|Name of Weapon: longsword}}. | Returns {{code|Name of Weapon: longsword}}. | ||
Line 29: | Line 29: | ||
[h: weapon = "name=longsword; damage=1d8; maxdamage=8"] | [h: weapon = "name=longsword; damage=1d8; maxdamage=8"] | ||
Minimum damage of Weapon: [r: getStrProp(weapon, "mindamage", 1)] | Minimum damage of Weapon: [r: getStrProp(weapon, "mindamage", 1)] | ||
</ | </syntaxhighlight> | ||
Returns {{code|Minimum damage of Weapon: 1}}. | Returns {{code|Minimum damage of Weapon: 1}}. | ||
Line 36: | Line 36: | ||
[h: weapon = "name=longsword: damage=1d8: maxdamage=8"] | [h: weapon = "name=longsword: damage=1d8: maxdamage=8"] | ||
Damage of Weapon: [r: getStrProp(weapon, "damage", "1d3", ":")] | Damage of Weapon: [r: getStrProp(weapon, "damage", "1d3", ":")] | ||
</ | </syntaxhighlight> | ||
Returns {{code|Damage of Weapon: 1d8}}. | Returns {{code|Damage of Weapon: 1d8}}. | ||
Revision as of 19:38, 14 March 2023
getStrProp() Function
Usage
<source lang="mtmacro" line> getStrProp(propList, key) getStrProp(propList, key, default) getStrProp(propList, key, default, delim) </syntaxhighlight> Parameters
proplist
- String property list to extract data from.key
- Key within string to extract. This cannot include a space.default
- Value returned if the key is not found.delim
- Delimiter between fields (default is ";").
Example
<source lang="mtmacro" line>
[h: weapon = "name=longsword; damage=1d8; maxdamage=8"]
Name of Weapon: [r: getStrProp(weapon, "name")]
</syntaxhighlight>
Returns Name of Weapon: longsword
.
To get the minimum damage from a weapon string property list with a default value should the key not exist
<source lang="mtmacro" line>
[h: weapon = "name=longsword; damage=1d8; maxdamage=8"]
Minimum damage of Weapon: [r: getStrProp(weapon, "mindamage", 1)]
</syntaxhighlight>
Returns Minimum damage of Weapon: 1
.
To get the damage from a weapon string property list where the field delimiter is a colon. The default is 1d3 (note that a default value must be provided in order to specify the delimiter). <source lang="mtmacro" line> [h: weapon = "name=longsword: damage=1d8: maxdamage=8"] Damage of Weapon: [r: getStrProp(weapon, "damage", "1d3", ":")] </syntaxhighlight>
ReturnsDamage of Weapon: 1d8
.
Version Changes
- 1.3b43 - Added the optional
error
parameter.