getStrProp: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
(Added missing param, "delim"; added more examples)
Line 8: Line 8:
<source lang="mtmacro" line>
<source lang="mtmacro" line>
getStrProp(propList, key)
getStrProp(propList, key)
</source>
getStrProp(propList, key, default)
<source lang="mtmacro" line>
getStrProp(propList, key, default, delim)
getStrProp(propList, key, error)
</source>
</source>
'''Parameters'''
'''Parameters'''
{{param|proplist|}}  
{{param|proplist|String list to extract data from.}}  
{{param|key|}}
{{param|key|Key within string to extract.}}
{{param|error|Returned if the key in not found.}}
{{param|default|Value returned if the key is not found.}}
{{param|delim|Delimiter between fields (default is ";").}}


|example=
|example=
Line 23: Line 23:
Name of Weapon = [r: getStrProp(weapon, "name")]
Name of Weapon = [r: getStrProp(weapon, "name")]
</source>
</source>
Returns {{code|longsword}}.
Returns {{code|Name of Weapon = longsword}}.
 
To get the minimum damage from a weapon [[Macros:string property list|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)]
</source>
Returns {{code|Minimum damage of Weapon = 1}}.
 
To get the damage from a weapon [[Macros:string property list|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", ":")]
</source>
Returns {{code|Damage of Weapon = 1d8}}.


|changes=
|changes=

Revision as of 17:11, 22 August 2010

getStrProp() Function

Introduced in version 1.3b42
Returns the value associated with a key from the specified string property list.

Usage

getStrProp(propList, key)
getStrProp(propList, key, default)
getStrProp(propList, key, default, delim)

Parameters

  • proplist - String list to extract data from.
  • key - Key within string to extract.
  • default - Value returned if the key is not found.
  • delim - Delimiter between fields (default is ";").

Example

To get the name from a weapon string property list
[h: weapon = "name=longsword; damage=1d8; maxdamage=8"]
Name of Weapon = [r: getStrProp(weapon, "name")]

Returns {{{1}}}.

To get the minimum damage from a weapon string property list with a default value should the key not exist

[h: weapon = "name=longsword; damage=1d8; maxdamage=8"]
Minimum damage of Weapon = [r: getStrProp(weapon, "mindamage", 1)]

Returns {{{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).

[h: weapon = "name=longsword: damage=1d8: maxdamage=8"]
Damage of Weapon = [r: getStrProp(weapon, "damage", "1d3", ":")]
Returns {{{1}}}.


Version Changes

  • 1.3b43 - Added the optional error parameter.