getMatchingProperties: Difference between revisions
Jump to navigation
Jump to search
m (Text replacement - "<source" to "<syntaxhighlight") |
m (Change example using colon (:) in a prop name which isn't allowed, to an underscore (_).) Tags: Reverted Visual edit |
||
Line 19: | Line 19: | ||
|examples= | |examples= | ||
Say you wanted to keep an inventory list for the [[Token]] you could prefix all of your inventory properties with {{code| | 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 | Then to loop through all of the inventory properties you could use | ||
<syntaxhighlight lang="mtmacro" line> | <syntaxhighlight lang="mtmacro" line> | ||
[foreach(item, getMatchingProperties(" | [foreach(item, getMatchingProperties("Inv_.*")): { | ||
<!-- Do something really exciting here --> | <!-- Do something really exciting here --> | ||
}] | }] | ||
Line 30: | Line 30: | ||
Or the following to loop through all the weapons | Or the following to loop through all the weapons | ||
<syntaxhighlight lang="mtmacro" line> | <syntaxhighlight lang="mtmacro" line> | ||
[foreach(item, getMatchingProperties(" | [foreach(item, getMatchingProperties("Inv_Weapon_.*")): { | ||
<!-- Do something really exciting here --> | <!-- Do something really exciting here --> | ||
}] | }] | ||
Line 37: | Line 37: | ||
Or even all the armor and all the shields. | Or even all the armor and all the shields. | ||
<syntaxhighlight lang="mtmacro" line> | <syntaxhighlight lang="mtmacro" line> | ||
[foreach(item, getMatchingProperties(" | [foreach(item, getMatchingProperties("Inv_(Armor|Shield)_.*")): { | ||
<!-- Do something really exciting here --> | <!-- Do something really exciting here --> | ||
}] | }] |
Revision as of 23:31, 8 September 2023
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)
getMatchingProperties(pattern, delim, id, mapname)
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 tokenid
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.
mapname
- The name of the map to find the token. Defaults to the current map.
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
Version Changes
- 1.5.4 - Added
mapname
parameter option.