movedOverToken: Difference between revisions
Jump to navigation
Jump to search
m (Conversion script moved page MovedOverToken to movedOverToken: Converting page titles to lowercase) |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 7: | Line 7: | ||
<!-- The 'nbsp' is needed to close the DIV --> | <!-- The 'nbsp' is needed to close the DIV --> | ||
|usage= | |usage= | ||
< | <syntaxhighlight lang="mtmacro"> | ||
movedOverToken(token) | movedOverToken(token) | ||
movedOverToken(token, lastPath) | movedOverToken(token, lastPath) | ||
</ | </syntaxhighlight> | ||
'''Parameters''' | '''Parameters''' | ||
{{param|token|The target token to compare the }} | {{param|token|The target token to compare the }} | ||
Line 18: | Line 18: | ||
A JSON array of cell coordinates where the moving token crossed the target token. | A JSON array of cell coordinates where the moving token crossed the target token. | ||
< | <syntaxhighlight lang="javascript"> | ||
[{"x":900,"y":400},{"x":900,"y":350},{"x":900,"y":300}] | [{"x":900,"y":400},{"x":900,"y":350},{"x":900,"y":300}] | ||
</ | </syntaxhighlight> | ||
|example= | |example= | ||
Check if the current token moved over a token called "Pit Trap". | Check if the current token moved over a token called "Pit Trap". | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[r: movedOverToken("Pit Trap")] | [r: movedOverToken("Pit Trap")] | ||
</ | </syntaxhighlight> | ||
'''Returns:''' | '''Returns:''' | ||
An array of coordinate pairs. In this case, just one. | An array of coordinate pairs. In this case, just one. | ||
< | <syntaxhighlight lang="mtmacro"> | ||
[{"x":550,"y":250}] | [{"x":550,"y":250}] | ||
</ | </syntaxhighlight> | ||
Count how many cells of caltrops the current token moved through. | Count how many cells of caltrops the current token moved through. | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[h: lastPath = getLastPath(1)] | [h: lastPath = getLastPath(1)] | ||
[h: locations = movedOverToken("Caltrops",lastPath)] | [h: locations = movedOverToken("Caltrops",lastPath)] | ||
Token moved over [r: json.length(locations)] caltrops. | Token moved over [r: json.length(locations)] caltrops. | ||
</ | </syntaxhighlight> | ||
'''Returns:''' | '''Returns:''' | ||
A count of the cells of the ''Caltrops'' token the current token moved over. | A count of the cells of the ''Caltrops'' token the current token moved over. | ||
To be clear: this ONLY works if you have ONE token on the maps called ''Caltrops'', if you want to check for multiple tokens you either need to use their ID or give them a unique name and refer to that. | To be clear: this ONLY works if you have ONE token on the maps called ''Caltrops'', if you want to check for multiple tokens you either need to use their ID or give them a unique name and refer to that. | ||
< | <syntaxhighlight lang="mtmacro"> | ||
Token moved over 3 caltrops. | Token moved over 3 caltrops. | ||
</ | </syntaxhighlight> | ||
|also= | |also= |
Latest revision as of 23:59, 14 March 2023
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 thelastPath
- 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.
To be clear: this ONLY works if you have ONE token on the maps called Caltrops, if you want to check for multiple tokens you either need to use their ID or give them a unique name and refer to that.
Token moved over 3 caltrops.