movedOverToken: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
mNo edit summary
(Updated with parameters and examples.)
Line 1: Line 1:
{{stub|lastPath-format specified, define/explain return value, examples}}
{{MacroFunction
{{MacroFunction
|name=movedOverToken
|name=movedOverToken
|version=1.3.b74
|version=1.3.b74
|description=
|description=
Is used to check if {{code|token}} is in an array of cell coordinates like the one received from {{func|getLastPath}} or the [[onTokenMove]] event's {{code|macro.args}}.
Is used to check if the location of the target {{code|token}} is in an array of cell coordinates like the one received from {{func|getLastPath}} or the [[onTokenMove]] event's {{code|macro.args}}.
 
 
<!-- The 'nbsp' is needed to close the DIV -->
<!-- The 'nbsp' is needed to close the DIV -->
|usage=
|usage=
<source lang="mtmacro">
movedOverToken(token)
movedOverToken(token, lastPath)
</source>
'''Parameters'''
{{param|token|The target token to compare the }}
{{param|lastPath|Optional JSON array of coordinate pairs.  If not supplied will use the last path of the current token.}}
'''Returns'''
A JSON array of cell coordinates where the moving token crossed the target token.
<source lang="javascript">
[{"x":900,"y":400},{"x":900,"y":350},{"x":900,"y":300}]
</source>
|example=
Check if the current token moved over a token called "Pit Trap".
<source lang="mtmacro" line>
[r: movedOverToken("Pit Trap")]
</source>
'''Returns:'''
An array of coordinate pairs. In this case, just one.
<source lang="mtmacro">
[{"x":550,"y":250}]
</source>
Count how many cells of caltrops the current token moved through.
<source lang="mtmacro" line>
<source lang="mtmacro" line>
movedOverToken(token, lastPath)
[h: lastPath = getLastPath(1)]
[h: locations = movedOverToken("Caltrops",lastPath)]
Token moved over [r: json.length(locations)] caltrops.
</source>
'''Returns:'''
A count of the cells of the ''Caltrops'' token the current token moved over.
<source lang="mtmacro">
Token moved over 3 caltrops.
</source>
</source>
|also=
{{func|getLastPath}} {{func|movedOverPoints}}


}}
}}
[[Category:Miscellaneous Function]]
[[Category:Miscellaneous Function]]

Revision as of 14:22, 26 August 2019

movedOverToken() Function

Introduced in version 1.3.b74
Is used to check if the location of the target token is in an array of cell coordinates like the one received from getLastPath() or the onTokenMove event's macro.args.  

Usage

movedOverToken(token)
movedOverToken(token, lastPath)

Parameters

  • token - The target token to compare the
  • lastPath - Optional JSON array of coordinate pairs. If not supplied will use the last path of the current token.

Returns

A JSON array of cell coordinates where the moving token crossed the target token.

[{"x":900,"y":400},{"x":900,"y":350},{"x":900,"y":300}]

Example

Check if the current token moved over a token called "Pit Trap".
[r: movedOverToken("Pit Trap")]

Returns: An array of coordinate pairs. In this case, just one.

[{"x":550,"y":250}]

Count how many cells of caltrops the current token moved through.

[h: lastPath = getLastPath(1)]
[h: locations = movedOverToken("Caltrops",lastPath)]
Token moved over [r: json.length(locations)] caltrops.

Returns: A count of the cells of the Caltrops token the current token moved over.

Token moved over 3 caltrops.

See Also