getMatchingLibProperties: Difference between revisions
Jump to navigation
Jump to search
m (Conversion script moved page GetMatchingLibProperties to getMatchingLibProperties: Converting page titles to lowercase) |
No edit summary |
||
Line 6: | Line 6: | ||
|usage= | |usage= | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
getMatchingLibProperties(pattern) | getMatchingLibProperties(pattern) | ||
</ | </syntaxhighlight> | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
getMatchingLibProperties(pattern, lib) | getMatchingLibProperties(pattern, lib) | ||
</ | </syntaxhighlight> | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
getMatchingLibProperties(pattern, lib, delim) | getMatchingLibProperties(pattern, lib, delim) | ||
</ | </syntaxhighlight> | ||
'''Parameters''' | '''Parameters''' | ||
{{param|pattern|A regular expression(regex) that represents the pattern the properties should match.}} | {{param|pattern|A regular expression(regex) that represents the pattern the properties should match.}} | ||
Line 24: | Line 24: | ||
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 | 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. | all the weapons. | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[foreach(item, getMatchingLibProperties("Weapon:.*", "Lib:Items")): { | [foreach(item, getMatchingLibProperties("Weapon:.*", "Lib:Items")): { | ||
<!-- Do something really exciting here --> | <!-- Do something really exciting here --> | ||
}] | }] | ||
</ | </syntaxhighlight> | ||
Or the following to loop through all the armor | Or the following to loop through all the armor | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[foreach(item, getMatchingLibProperties("Armor:.*", "Lib:Items")): { | [foreach(item, getMatchingLibProperties("Armor:.*", "Lib:Items")): { | ||
<!-- Do something really exciting here --> | <!-- Do something really exciting here --> | ||
}] | }] | ||
</ | </syntaxhighlight> | ||
Or even all the armor and all the shields. | Or even all the armor and all the shields. | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[foreach(item, getMatchingLibProperties("(Armor|Shield):.*", "Lib:Items")): { | [foreach(item, getMatchingLibProperties("(Armor|Shield):.*", "Lib:Items")): { | ||
<!-- Do something really exciting here --> | <!-- Do something really exciting here --> | ||
}] | }] | ||
</ | </syntaxhighlight> | ||
Revision as of 18:40, 14 March 2023
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 -->
}]