getStrProp: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(New page: ==Function getStrProp== Returns the value associated with a key from the specified Macros:string property list. ==Usage== <source lang="mtmacro" line> [h: macros = getStrProp(propL...)
 
m (Text replacement - "<source" to "<syntaxhighlight")
 
(15 intermediate revisions by 8 users not shown)
Line 1: Line 1:
==Function getStrProp==
{{MacroFunction
 
|name=getStrProp
|version=1.3b42
|description=
Returns the value associated with a key from the specified [[Macros:string property list|string property list]].  
Returns the value associated with a key from the specified [[Macros:string property list|string property list]].  


==Usage==
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: macros = getStrProp(propList, key)]
getStrProp(propList, key)
</source>
getStrProp(propList, key, default)
getStrProp(propList, key, default, delim)
</syntaxhighlight>
'''Parameters'''
{{param|proplist|String property list to extract data from.}}
{{param|key|Key within string to extract. This cannot include a space.}}
{{param|default|Value returned if the key is not found.}}
{{param|delim|Delimiter between fields (default is ";").}}


|example=
To get the name from a weapon [[Macros:string property list|string property list]]
<syntaxhighlight lang="mtmacro" line>
[h: weapon = "name=longsword; damage=1d8; maxdamage=8"]
Name of Weapon: [r: getStrProp(weapon, "name")]
</syntaxhighlight>
Returns {{code|Name of Weapon: longsword}}.


===Examples===
To get the minimum damage from a weapon [[Macros:string property list|string property list]] with a default value should the key not exist
To get the name from a weapon [[Macros:string property list|string property list]]
<syntaxhighlight lang="mtmacro" line>
<source lang="mtmacro" line>
[h: weapon = "name=longsword; damage=1d8; maxdamage=8"]
[h: weapon = "name=longsword; damage=1d8; maxdamage=8"]
Name of Weapon = [r: getStrProp(weapon, "name"]
Minimum damage of Weapon: [r: getStrProp(weapon, "mindamage", 1)]
</source>
</syntaxhighlight>
Returns "longsword".
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).
<syntaxhighlight lang="mtmacro" line>
[h: weapon = "name=longsword: damage=1d8: maxdamage=8"]
Damage of Weapon: [r: getStrProp(weapon, "damage", "1d3", ":")]
</syntaxhighlight>
Returns {{code|Damage of Weapon: 1d8}}.
 
|changes=
{{change|1.3b43|Added the optional {{code|error}} parameter.}}
 
}}
[[Category:String Property List Function]]

Latest revision as of 23:59, 14 March 2023

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 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

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 Name of Weapon: longsword.

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

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


Version Changes

  • 1.3b43 - Added the optional error parameter.