getMatchingProperties: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(Initial write-up.)
 
No edit summary
Line 1: Line 1:
{{stub|Corrections to possibly inaccurate information. Examples of usage.}}
{{MacroFunction
{{MacroFunction
|name=getMatchingProperties
|name=getMatchingProperties
Line 20: Line 19:
{{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}} }}
{{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=
Say you wanted to keep an inventory list for the [[Token]] you could prefix all of your inventory properties with {{code|Inv:''Category'':}}. For example {{code|Inv:Weapon:Longsword}}.
Then to loop through all of the inventory properties you could use
<source lang="mtmacro" line>
[foreach(item, getMatchingProperties("Inv:.*")): {
    <!-- Do something really exciting here -->
}]
</source>
Or the following to loop through all the weapons
<source lang="mtmacro" line>
[foreach(item, getMatchingProperties("Inv:Weapon:.*")): {
    <!-- Do something really exciting here -->
}]
</source>
Or even all the armor and all the shields.
<source lang="mtmacro" line>
[foreach(item, getMatchingProperties("Inv:(Armor|Shield):.*")): {
    <!-- Do something really exciting here -->
}]
</source>


|also=
|also=
{{func|getMatchingLibProperties}}
{{func|getMatchingLibProperties}} {{func|getPropertyNames}}


}}
}}

Revision as of 02:02, 1 April 2009

getMatchingProperties() Function

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

Usage

getMatchingProperties(pattern)
getMatchingProperties(pattern, delim)
getMatchingProperties(pattern, delim, id)

Parameters

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

     Note: This parameter can only be used in a Trusted Macro

Examples

Say you wanted to keep an inventory list for the Token you could prefix all of your inventory properties with Inv:Category:. For example Inv:Weapon:Longsword.

Then to loop through all of the inventory properties you could use

[foreach(item, getMatchingProperties("Inv:.*")): {
    <!-- Do something really exciting here -->
}]

Or the following to loop through all the weapons

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

Or even all the armor and all the shields.

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

See Also