getInitiativeList: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Update for 1.3b78)
No edit summary
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{stub|more examples.}}
{{MacroFunction
{{MacroFunction
|name=getInitiativeList
|name=getInitiativeList
|version=1.3.b61 (?)
|version=1.3b57
|description=
|description=
Retrieves a list of all tokens currently in the Initiative Panel.  The return value is a JSON object with various information about initiative, including global information (round number, which map is current, which token is current) and token-specific information (token id, initiative value, whether the token is holding or not).
Retrieves a list of all tokens currently in the Initiative Panel.  The return value is a JSON object with various information about initiative, including global information (round number, which map is current, which token is current) and token-specific information (token id, initiative value, whether the token is holding or not).
Line 9: Line 8:


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[ json = getInitiativeList() ]
[ json = getInitiativeList() ]
</source>
</syntaxhighlight>
'''Parameters'''
'''Parameters'''
None.
None.
Line 17: Line 16:
|example=
|example=
The following code will simply return a JSON object and print each property name one at a time on separate lines.  Refer to [[JSON Object]] for more information about JSON object themselves and [[json.get]] for information on retrieving properties and their values.
The following code will simply return a JSON object and print each property name one at a time on separate lines.  Refer to [[JSON Object]] for more information about JSON object themselves and [[json.get]] for information on retrieving properties and their values.
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: json = getInitiativeList() ]
[h: json = getInitiativeList() ]
[ foreach(item, json, "<br>"): item ]
[r, foreach(item, json, "<br>"), code: {
</source>
  [r: item]: [r:json.get(json,item)]
}]
</syntaxhighlight>
'''Output'''
 
A list of the key/value pairs in the object returned.
<syntaxhighlight lang="mtmacro">
round: Round Number
map: Map Name
current: Current Position in List
tokens: An Array of Objects for Each Token in List
</syntaxhighlight>


This example prints a nicely formatted output showing what the contents of the JSON object look like.
This example prints a nicely formatted output showing what the contents of the JSON object look like.
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: json = getInitiativeList() ]
[h: json = getInitiativeList() ]
<pre>[r: json.indent(json) ]</pre>
<pre>[r: json.indent(json) ]</pre>
</source>
</syntaxhighlight>
 
'''Output'''
<syntaxhighlight lang="javascript">
{
  "round": 1,
  "map": "Grasslands",
  "current": 1,
  "tokens":  [
        {
      "holding": false,
      "initiative": "20",
      "tokenId": "3C2518218E5E4D088F96FAE93A048357"
    },
        {
      "holding": false,
      "initiative": "17",
      "tokenId": "8FA88395DA264D04B1B6F0F0E38A7692"
    },
        {
      "holding": false,
      "initiative": "13",
      "tokenId": "066CDB7953B74F239952AD82D4147433"
    },
        {
      "holding": false,
      "initiative": "10",
      "tokenId": "AF6D8BEB95C6424287E09206AD155120"
    },
        {
      "holding": false,
      "initiative": "3",
      "tokenId": "27B65E37216F4A02BCE59899CE2048AA"
    },
        {
      "holding": false,
      "initiative": "1",
      "tokenId": "4F06F4B20A954D719B9788F07EB923BE"
    }
  ]
}
</syntaxhighlight>


|changes=
|changes=
{{change|1.3b61|Added macro function (could have been b60)}}
{{change|1.3b57|Added macro function.}}
{{change|1.3b78|Filters output based on trusted status.}}
}}
}}
[[Category:Initiative Function]]
[[Category:Initiative Function]]

Latest revision as of 23:59, 14 March 2023

getInitiativeList() Function

Introduced in version 1.3b57
Retrieves a list of all tokens currently in the Initiative Panel. The return value is a JSON object with various information about initiative, including global information (round number, which map is current, which token is current) and token-specific information (token id, initiative value, whether the token is holding or not). When called from a Trusted Macro or by a client with GM authority, it will return all information. Otherwise it only returns information visible to the current player. In other words, it respects the Initiative Panel's Hide NPCs and the token's Visible To Owner Only flags, among others. (This is new in 1.3b78. Prior versions didn't have the check for trusted context at all.)

Usage

[ json = getInitiativeList() ]

Parameters None.

Example

The following code will simply return a JSON object and print each property name one at a time on separate lines. Refer to JSON Object for more information about JSON object themselves and json.get for information on retrieving properties and their values.
[h: json = getInitiativeList() ]
[r, foreach(item, json, "<br>"), code: {
  [r: item]: [r:json.get(json,item)]
}]

Output

A list of the key/value pairs in the object returned.

round: Round Number
map: Map Name
current: Current Position in List
tokens: An Array of Objects for Each Token in List

This example prints a nicely formatted output showing what the contents of the JSON object look like.

[h: json = getInitiativeList() ]
<pre>[r: json.indent(json) ]</pre>

Output

{
  "round": 1,
  "map": "Grasslands",
  "current": 1,
  "tokens":   [
        {
      "holding": false,
      "initiative": "20",
      "tokenId": "3C2518218E5E4D088F96FAE93A048357"
    },
        {
      "holding": false,
      "initiative": "17",
      "tokenId": "8FA88395DA264D04B1B6F0F0E38A7692"
    },
        {
      "holding": false,
      "initiative": "13",
      "tokenId": "066CDB7953B74F239952AD82D4147433"
    },
        {
      "holding": false,
      "initiative": "10",
      "tokenId": "AF6D8BEB95C6424287E09206AD155120"
    },
        {
      "holding": false,
      "initiative": "3",
      "tokenId": "27B65E37216F4A02BCE59899CE2048AA"
    },
        {
      "holding": false,
      "initiative": "1",
      "tokenId": "4F06F4B20A954D719B9788F07EB923BE"
    }
  ]
}


Version Changes

  • 1.3b57 - Added macro function.
  • 1.3b78 - Filters output based on trusted status.