getDistanceToXY
getDistanceToXY() Function
Usage
<source lang="mtmacro" line> getDistanceToXY(x, y) getDistanceToXY(x, y, units) getDistanceToXY(x, y, units, source) getDistanceToXY(x, y, units, source, metric) getDistanceToXY(x, y, units, source, metric, pixels) </syntaxhighlight> 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
- The id 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
).
Example
<source lang="mtmacro" line> [h: dist = getDistanceToXY(10, 10)] </syntaxhighlight>
To get the distance between the Altar and 10, 10 in the number of squares or hexes. <source lang="mtmacro" line> [h: dist = getDistanceToXY(10, 10, 0, "Altar")] </syntaxhighlight>
To get the distance between the Altar and 10, 10 in map distance units. <source lang="mtmacro" line> [h: dist = getDistanceToXY(10, 10, 1, "Altar")] </syntaxhighlight>
To get the straight line distance between the Altar and 10, 10. <source lang="mtmacro" line> [h: dist = getDistanceToXY(10, 10, 1, "Altar", "NO_GRID")]
</syntaxhighlight>See Also
Version Changes
- 1.3b55 - Added the optional
metric
argument. - 1.5.5 - Added the
pixel
argument.