getLights: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Conversion script moved page GetLights to getLights: Converting page titles to lowercase)
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 5: Line 5:


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
getLights()
getLights()
getLights(type)
getLights(type)
getLights(type, delim)
getLights(type, delim)
getLights(type, delim, id)
getLights(type, delim, tokenRef)
getLights(type, delim, id, mapname)
getLights(type, delim, tokenRef, mapRef)
</source>
</syntaxhighlight>


'''Parameters'''
'''Parameters'''
{{param|type|The light source type, (e.g. "Generic", "D20"). If set to "*", all light sources are returned. Defaults to "*".}}
{{param|type|The light source type, (e.g. "Generic", "D20"). If set to "*", all light sources are returned. Defaults to "*".}}
{{param|delim|The delimiter used to separate values in the [[Macros:string list{{!}}string list]]. If set to "json", a [[JSON Array]] is returned. Defaults to ",".}}
{{param|delim|The delimiter used to separate values in the [[Macros:string list{{!}}string list]]. If set to "json", a [[JSON Array]] is returned. Defaults to ",".}}
{{param|id|The token {{code|id}} of the token to change the light sources, defaults to the [[Current Token]]. {{TrustedParameter}} }}
{{param|tokenRef|Either the token [[getSelected|{{code|id}}]] or [[getTokenName|Token Name]] of the token to list the light sources, defaults to the [[Current Token]]. {{TrustedParameter}} }}
{{param|mapname|The name of the map to find the token.  Defaults to the current map.}}
{{param|mapRef|The Name or ID of the map to find the token.  Defaults to the current map.}}
{{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.}}


|examples=
|examples=
To get a [[Macros:string list{{!}}string list]] of all of the [[Introduction to Lights and Sights|light source]]s that the current [[Token:token{{!}}token]] has on.
To get a [[Macros:string list{{!}}string list]] of all of the [[Introduction to Lights and Sights|light source]]s that the current [[Token:token{{!}}token]] has on.
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[getLights()]
[getLights()]
</source>
</syntaxhighlight>


To get a [[Macros:string list{{!}}string list]] of the [[Introduction to Lights and Sights|light source]]s that the current [[Token:token{{!}}token]] has on with the light source type of "Generic".
To get a [[Macros:string list{{!}}string list]] of the [[Introduction to Lights and Sights|light source]]s that the current [[Token:token{{!}}token]] has on with the light source type of "Generic".
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[getLights("Generic")]
[getLights("Generic")]
</source>
</syntaxhighlight>


'''Getting all lights from campaign properties'''<br>
'''Getting all lights from campaign properties'''<br>
The information provided by [[getInfo]] can be used to extract all light source names defined in the campaign properties. The following provides all names in a [[JSON Array]]:
The information provided by [[getInfo]] can be used to extract all light source names defined in the campaign properties. The following provides all names in a [[JSON Array]]:
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: json.path.read(json.get(getInfo("campaign"), "light sources"), ".[*][*]['name']")]
[r: json.path.read(json.get(getInfo("campaign"), "light sources"), ".[*][*]['name']")]
</source>
</syntaxhighlight>


To restrict the query to only one specific type of light sources, you can use the following and replace {{code|'TYPE'}} with the desired type (note that single quotes are needed for this string, because double quotes are already in use):
To restrict the query to only one specific type of light sources, you can use the following and replace {{code|'TYPE'}} with the desired type (note that single quotes are needed for this string, because double quotes are already in use):
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[r: json.path.read(json.get(getInfo("campaign"), "light sources"), ".['TYPE'][*]['name']")]
[r: json.path.read(json.get(getInfo("campaign"), "light sources"), ".['TYPE'][*]['name']")]
</source>
</syntaxhighlight>


|changes=
|changes=

Latest revision as of 23:59, 13 May 2024

getLights() Function

Introduced in version 1.3b48
Returns a string list containing the names of the light sources that are turned on for the Current Token. The type of the value returned depends on the delimiter parameter.

Usage

getLights()
getLights(type)
getLights(type, delim)
getLights(type, delim, tokenRef)
getLights(type, delim, tokenRef, mapRef)

Parameters

  • type - The light source type, (e.g. "Generic", "D20"). If set to "*", all light sources are returned. Defaults to "*".
  • delim - The delimiter used to separate values in the string list. If set to "json", a JSON Array is returned. Defaults to ",".
  • tokenRef - Either the token id or Token Name of the token to list the light sources, defaults to the Current Token.

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

  • mapRef - The Name or ID of the map to find the token. Defaults to the current map.
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.

Examples

To get a string list of all of the light sources that the current token has on.
[getLights()]

To get a string list of the light sources that the current token has on with the light source type of "Generic".

[getLights("Generic")]

Getting all lights from campaign properties
The information provided by getInfo can be used to extract all light source names defined in the campaign properties. The following provides all names in a JSON Array:

[r: json.path.read(json.get(getInfo("campaign"), "light sources"), ".[*][*]['name']")]

To restrict the query to only one specific type of light sources, you can use the following and replace 'TYPE' with the desired type (note that single quotes are needed for this string, because double quotes are already in use):

[r: json.path.read(json.get(getInfo("campaign"), "light sources"), ".['TYPE'][*]['name']")]

Version Changes

  • 1.3b49 - Added "json" delimiter option.
  • 1.5.4 - Added id and mapname parameter options.