getMatchingLibProperties: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(Initial write-up.)
 
(Updated details, see also, and examples)
Line 1: Line 1:
{{stub|Corrections to incomplete or possibly inaccurate information. Examples of usage.}}
{{MacroFunction
{{MacroFunction
|name=getMatchingLibProperties
|name=getMatchingLibProperties
Line 15: Line 14:
<source lang="mtmacro" line>
<source lang="mtmacro" line>
getMatchingLibProperties(pattern, lib, delim)
getMatchingLibProperties(pattern, lib, delim)
</source>
<source lang="mtmacro" line>
getMatchingLibProperties(pattern, lib, delim, id)
</source>
</source>
'''Parameters'''
'''Parameters'''
Line 23: Line 19:
{{param|lib|The name of the [[Library Token]] that is checked for properties that match, defaults to the [[Library Token]] the macro is running on.}}
{{param|lib|The name of the [[Library Token]] that is checked for properties that match, defaults to the [[Library Token]] the macro is running on.}}
{{param|delim|The delimiter used in the [[String List]] that is returned, defaults to {{code|","}}.  Returns a [[JSON Array]] if {{code|"json"}} is specified.}}
{{param|delim|The delimiter used in the [[String List]] that is returned, defaults to {{code|","}}.  Returns a [[JSON Array]] if {{code|"json"}} is specified.}}
{{param|id|The token {{code|id}} of the token that is checked for properties that match the given pattern, defaults to the [[Current Token]]. {{TrustedParameter}} }}
 
 
|examples=
Assuming that you have a [[Library Token]] that contained a list of all the items and their detail in your campaign stored as [[Token]] properties names with the following format {{code|''Type'':''Item Name''}} (for example {{code|Weapon:Longsword)}}, you could use the following code to loop through
all the weapons.
<source lang="mtmacro" line>
[foreach(item, getMatchingLibProperties("Weapon:.*", "Lib:Items")): {
    <!-- Do something really exciting here -->
}]
</source>
 
Or the following to loop through all the armor
<source lang="mtmacro" line>
[foreach(item, getMatchingLibProperties("Armor:.*", "Lib:Items")): {
    <!-- Do something really exciting here -->
}]
</source>
 
Or even all the armor and all the shields.
<source lang="mtmacro" line>
[foreach(item, getMatchingLibProperties("(Armor|Shield):.*", "Lib:Items")): {
    <!-- Do something really exciting here -->
}]
</source>
 


|also=
|also=
{{func|getMatchingProperties}}
{{func|getMatchingProperties}} {{func|getLibPropertyNames}}


}}
}}

Revision as of 01:42, 1 April 2009

getMatchingLibProperties() Function

Introduced in version 1.3b54
Returns a String List or JSON Array with names of the Token Properties on a specific Library Token that match the given pattern.

Usage

getMatchingLibProperties(pattern)
getMatchingLibProperties(pattern, lib)
getMatchingLibProperties(pattern, lib, delim)

Parameters

  • pattern - A regular expression(regex) that represents the pattern the properties should match.
  • lib - The name of the Library Token that is checked for properties that match, defaults to the Library Token the macro is running on.
  • delim - The delimiter used in the String List that is returned, defaults to ",". Returns a JSON Array if "json" is specified.

Examples

Assuming that you have a Library Token that contained a list of all the items and their detail in your campaign stored as Token properties names with the following format Type:Item Name (for example Weapon:Longsword), you could use the following code to loop through

all the weapons.

[foreach(item, getMatchingLibProperties("Weapon:.*", "Lib:Items")): {
    <!-- Do something really exciting here -->
}]

Or the following to loop through all the armor

[foreach(item, getMatchingLibProperties("Armor:.*", "Lib:Items")): {
    <!-- Do something really exciting here -->
}]

Or even all the armor and all the shields.

[foreach(item, getMatchingLibProperties("(Armor|Shield):.*", "Lib:Items")): {
    <!-- Do something really exciting here -->
}]

See Also