selectTokens: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Fixed variable name)
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 6: Line 6:


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
selectTokens()
selectTokens()
</source>
</syntaxhighlight>
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
selectTokens(id, add)
selectTokens(tokenRef, add)
</source>
</syntaxhighlight>
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
selectTokens(tokens, add, delim)
selectTokens(tokens, add, delim)
</source>
</syntaxhighlight>


'''Parameter'''
'''Parameter'''
* {{code|id}} - the id string or token name of a specific token to select (the examples below use token ''names'', but IDs are also permitted); if left blank ''all'' visible tokens are selected.
* {{code|tokenRef}} - Either the token [[getSelected|{{code|id}}]] or [[getTokenName|Token Name]] of the token to select (the examples below use token ''names'', but IDs are also permitted); if left blank ''all'' visible tokens are selected.
* {{code|add}} - if the value of add is {{code|true(1)}}, the selections will be added to the current set of selected tokens; if the value is {{code|false(0)}} currently selected tokens will be deselected before new tokens are selected. Defaults to false.  
* {{code|add}} - if the value of add is {{code|true(1)}}, the selections will be added to the current set of selected tokens; if the value is {{code|false(0)}} currently selected tokens will be deselected before new tokens are selected. Defaults to false.  
* {{code|tokens}} - a [[String List]] of tokens to select.
* {{code|tokens}} - a [[String List]] of tokens to select.
* {{code|delim}} - Specifies the delimiter used in the string list that is supplied. If the delimiter is "json", then the value for {{code|tokens}} may be a [[JSON Array]] instead. '''Note: if using a JSON Array or String List, both {{code|add}} and {{code|delim}} must be specified.'''
* {{code|delim}} - Specifies the delimiter used in the string list that is supplied. If the delimiter is "json", then the value for {{code|tokens}} may be a [[JSON Array]] instead. '''Note: if using a JSON Array or String List, both {{code|add}} and {{code|delim}} must be specified.'''
{{Note|Token IDs are unique, but Token Names can be duplicated. Using Token Name when more than one token has the same name can produce unexpected results.}}


|example=
|example=
To select a single token with the name "Adventurer":
To select a single token with the name "Adventurer":
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h:selectTokens("Adventurer")]
[h:selectTokens("Adventurer")]
</source>
</syntaxhighlight>


To select a list of [[Token]]s using a [[String List]], replacing the current selection
To select a list of [[Token]]s using a [[String List]], replacing the current selection
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h:selectTokens("Adventurer, Orc 2, Goblin 1", 0, ",")]
[h:selectTokens("Adventurer, Orc 2, Goblin 1", 0, ",")]
</source>
</syntaxhighlight>


To select a list of [[Token]]s using a [[JSON Array]], adding the specified tokens to the current set of selected [[Token]]s:
To select a list of [[Token]]s using a [[JSON Array]], adding the specified tokens to the current set of selected [[Token]]s:
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h:selectTokens("['Adventurer', 'Orc 2', 'Goblin 1']", 1, "json")]
[h:selectTokens("['Adventurer', 'Orc 2', 'Goblin 1']", 1, "json")]
</source>
</syntaxhighlight>


|also=
|also=

Latest revision as of 23:31, 22 May 2024

selectTokens() Function

Introduced in version 1.3b68
Selects one or more visible tokens on the map.

Usage

selectTokens()
selectTokens(tokenRef, add)
selectTokens(tokens, add, delim)

Parameter

  • tokenRef - Either the token id or Token Name of the token to select (the examples below use token names, but IDs are also permitted); if left blank all visible tokens are selected.
  • add - if the value of add is true(1), the selections will be added to the current set of selected tokens; if the value is false(0) currently selected tokens will be deselected before new tokens are selected. Defaults to false.
  • tokens - a String List of tokens to select.
  • delim - Specifies the delimiter used in the string list that is supplied. If the delimiter is "json", then the value for tokens may be a JSON Array instead. Note: if using a JSON Array or String List, both add and delim must be specified.
Token IDs are unique, but Token Names can be duplicated. Using Token Name when more than one token has the same name can produce unexpected results.

Example

To select a single token with the name "Adventurer":
[h:selectTokens("Adventurer")]

To select a list of Tokens using a String List, replacing the current selection

[h:selectTokens("Adventurer, Orc 2, Goblin 1", 0, ",")]

To select a list of Tokens using a JSON Array, adding the specified tokens to the current set of selected Tokens:

[h:selectTokens("['Adventurer', 'Orc 2', 'Goblin 1']", 1, "json")]

See Also

Version Changes

  • 1.3b68 - Function added.