getDistanceToXY: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(8 intermediate revisions by 3 users not shown) | |||
Line 6: | Line 6: | ||
|usage= | |usage= | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
getDistanceToXY(x, y) | getDistanceToXY(x, y) | ||
getDistanceToXY(x, y, units) | getDistanceToXY(x, y, units) | ||
getDistanceToXY(x, y, units, source) | getDistanceToXY(x, y, units, source tokenRef) | ||
getDistanceToXY(x, y, units, source, metric) | getDistanceToXY(x, y, units, source tokenRef, metric) | ||
getDistanceToXY(x, y, units, source, metric, pixels) | getDistanceToXY(x, y, units, source tokenRef, metric, pixels) | ||
</ | </syntaxhighlight> | ||
'''Parameters''' | '''Parameters''' | ||
{{param|x|The X coordinate of the target grid cell.}} | |||
{{param|y|The Y coordinate of the target grid cell.}} | |||
{{param|units|If set to {{false}}, the distance is returned in cells. Default is returning Distance Per Cell units.}} | |||
{{param|source tokenRef|Either the token [[getSelected|{{code|id}}]] or [[getTokenName|Token Name]] of the token to measure the distance from. Default is the current token.}} | |||
{{param|metric|The movement metric to use which defaults to the movement metric in the users preferences, the metric can be one of the following strings}} | |||
** {{code|NO_GRID}} - The grid is ignored and straight line distance between the | ** {{code|NO_GRID}} - The grid is ignored and straight line distance between the center of the token and the center of the cell is returned. | ||
** {{code|ONE_TWO_ONE}} - First Diagonal movement costs 1, second 2, and so on (Square grid only). | ** {{code|ONE_TWO_ONE}} - First Diagonal movement costs 1, second 2, and so on (Square grid only). | ||
** {{code|ONE_ONE_ONE}} - Diagonal movement costs a single square (Square grid only). | ** {{code|ONE_ONE_ONE}} - Diagonal movement costs a single square (Square grid only). | ||
** {{code|MANHATTAN}} - Diagonal movement costs 2 (Square grid only). | ** {{code|MANHATTAN}} - Diagonal movement costs 2 (Square grid only). | ||
** {{code|NO_DIAGONALS}} - No diagonal movement is allowed (Square grid only). | ** {{code|NO_DIAGONALS}} - No diagonal movement is allowed (Square grid only). | ||
{{param|pixel|If set to {{true}}, the X and Y refer to pixels. If set to {{false}}, they refer to a cell. Default to {{false}}.}} | |||
{{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.}} | |||
|example= | |example= | ||
To get the distance from the current token to 10,10. | To get the distance from the current token to 10,10. | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[h: dist = getDistanceToXY(10, 10)] | [h: dist = getDistanceToXY(10, 10)] | ||
</ | </syntaxhighlight> | ||
To get the distance between the ''Altar'' and 10, 10 in the number of squares or hexes. | To get the distance between the ''Altar'' and 10, 10 in the number of squares or hexes. | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[h: dist = getDistanceToXY(10, 10, 0, "Altar")] | [h: dist = getDistanceToXY(10, 10, 0, "Altar")] | ||
</ | </syntaxhighlight> | ||
To get the distance between the ''Altar'' and 10, 10 in ''map distance'' units. | To get the distance between the ''Altar'' and 10, 10 in ''map distance'' units. | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[h: dist = getDistanceToXY(10, 10, 1, "Altar")] | [h: dist = getDistanceToXY(10, 10, 1, "Altar")] | ||
</ | </syntaxhighlight> | ||
To get the straight line distance between the ''Altar'' and 10, 10. | To get the straight line distance between the ''Altar'' and 10, 10. | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[h: dist = getDistanceToXY(10, 10, 1, "Altar", "NO_GRID")] | [h: dist = getDistanceToXY(10, 10, 1, "Altar", "NO_GRID")] | ||
</ | </syntaxhighlight> | ||
|also= | |also= | ||
Line 52: | Line 53: | ||
|changes= | |changes= | ||
{{change|1.3b55|Added the optional {{code|metric}} argument.}} | {{change|1.3b55|Added the optional {{code|metric}} argument.}} | ||
{{change|1.5.5|Added the {{code|pixel}} argument.}} | |||
}} | }} | ||
[[Category:Distance Function]] | [[Category:Distance Function]] |
Latest revision as of 23:59, 13 May 2024
getDistanceToXY() Function
• Introduced in version 1.3b51
Gets the distance to a target grid cell.
Usage
getDistanceToXY(x, y)
getDistanceToXY(x, y, units)
getDistanceToXY(x, y, units, source tokenRef)
getDistanceToXY(x, y, units, source tokenRef, metric)
getDistanceToXY(x, y, units, source tokenRef, metric, pixels)
Parameters
x
- The X coordinate of the target grid cell.y
- The Y coordinate of the target grid cell.units
- If set tofalse
(0
), the distance is returned in cells. Default is returning Distance Per Cell units.source tokenRef
- Either the tokenid
or Token Name of the token to measure the distance from. Default is the current token.metric
- The movement metric to use which defaults to the movement metric in the users preferences, the metric can be one of the following stringsNO_GRID
- The grid is ignored and straight line distance between the center of the token and the center of the cell is returned.ONE_TWO_ONE
- First Diagonal movement costs 1, second 2, and so on (Square grid only).ONE_ONE_ONE
- Diagonal movement costs a single square (Square grid only).MANHATTAN
- Diagonal movement costs 2 (Square grid only).NO_DIAGONALS
- No diagonal movement is allowed (Square grid only).
pixel
- If set totrue
(1
), the X and Y refer to pixels. If set tofalse
(0
), they refer to a cell. Default tofalse
(0
).
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.
Example
To get the distance from the current token to 10,10.
[h: dist = getDistanceToXY(10, 10)]
To get the distance between the Altar and 10, 10 in the number of squares or hexes.
[h: dist = getDistanceToXY(10, 10, 0, "Altar")]
To get the distance between the Altar and 10, 10 in map distance units.
[h: dist = getDistanceToXY(10, 10, 1, "Altar")]
To get the straight line distance between the Altar and 10, 10.
[h: dist = getDistanceToXY(10, 10, 1, "Altar", "NO_GRID")]
See Also
Version Changes
- 1.3b55 - Added the optional
metric
argument. - 1.5.5 - Added the
pixel
argument.