getWithState: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Fix MTScript code formatting)
 
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
==Function getWithState==
{{MacroFunction
{{TrustedOnlyFunction}}
|name=getWithState
 
|trusted=true
 
|version=1.3b48
Gets a list containing the ids of all the [[Token:token|token]]s on the current [[Map:map|map]] that have the specified [[Token:state | token state]] set. The type of the value returned depends on the delimiter parameter.  
|description=
* If the delimiter is not specified then a [[Macros:string list|string list]] is returned with the default value of ',' is used.
Gets a list containing the ids of all the [[Token:token|token]]s on the current [[Introduction to Mapping|map]] that have the specified [[Token:state | token state]] set. The type of the value returned depends on the delimiter parameter.  
* If the delimiter ''"json"'' then a [[Macros:json array|json array]] is returned. '''(as of MapTool 1.3b49)'''
* If the delimiter is not specified then a [[Macros:string list|string list]] is returned with the default value of {{code|","}} is used.
* If the delimiter {{code|json}} then a [[JSON Array]] is returned.
* Otherwise a [[Macros:string list|string list]] is returned with the delimiter passed in.
* Otherwise a [[Macros:string list|string list]] is returned with the delimiter passed in.
 


===Usage===
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: ids = getWithState(state)]
getWithState(state)
[h: ids = getWithState(state, delim)]
getWithState(state, delim)
</source>
</syntaxhighlight>


If delim is specified then it is used to separate the values in the list, if it is not specified then it defaults to ','.
If {{code|delim}} is specified then it is used to separate the values in the list, if it is not specified then it defaults to {{code|","}}.


===Examples===
|example=
You can use the following code to print out the ids of all of the [[Token:token|token]]s on the current [[Map:map|map]] with the "Dead" [[Token:state| token state]] set.
You can use the following code to print out the ids of all of the [[Token:token|token]]s on the current [[Introduction to Mapping|map]] with the "Dead" [[Token:state| token state]] set.
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: ids = getWithState("Dead")]
[h: ids = getWithState("Dead")]
[foreach(id, ids, "<br>"): id]
[foreach(id, ids, "<br>"): id]
</source>
</syntaxhighlight>
 
|changes=
* '''1.3b49''' - Added {{code|json}} delimiter option.
}}
[[Category:Find Function]]
[[Category:State Function]]
[[Category:Token Function]]

Latest revision as of 21:02, 20 June 2023

getWithState() Function

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

Introduced in version 1.3b48
Gets a list containing the ids of all the tokens on the current map that have the specified token state set. The type of the value returned depends on the delimiter parameter.
  • If the delimiter is not specified then a string list is returned with the default value of "," is used.
  • If the delimiter json then a JSON Array is returned.
  • Otherwise a string list is returned with the delimiter passed in.
 

Usage

getWithState(state)
getWithState(state, delim)

If delim is specified then it is used to separate the values in the list, if it is not specified then it defaults to ",".

Example

You can use the following code to print out the ids of all of the tokens on the current map with the "Dead" token state set.
[h: ids = getWithState("Dead")]
[foreach(id, ids, "<br>"): id]


Version Changes

  • 1.3b49 - Added json delimiter option.