getDistanceToXY: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Formating fixes)
No edit summary
Line 8: Line 8:
<source lang="mtmacro" line>
<source lang="mtmacro" line>
getDistanceToXY(x, y)
getDistanceToXY(x, y)
</source>
<source lang="mtmacro" line>
getDistanceToXY(x, y, units)
getDistanceToXY(x, y, units)
</source>
<source lang="mtmacro" line>
getDistanceToXY(x, y, units, source)
getDistanceToXY(x, y, units, source)
</source>
<source lang="mtmacro" line>
getDistanceToXY(x, y, units, source, metric)
getDistanceToXY(x, y, units, source, metric)
getDistanceToXY(x, y, units, source, metric, pixels)
</source>
</source>
'''Parameters'''
'''Parameters'''
* {{code|x}} - The X coordinate of the target grid cell.
* {{param|x}}The X coordinate of the target grid cell.
* {{code|y}} - The Y coordinate of the target grid cell.
* {{param|y}}The Y coordinate of the target grid cell.
* {{code|units}} - If set to {{code|false}}({{code|0}}) the distance is returned in cells. Default is returning Distance Per Cell units.
* {{param|units}}If set to {{false}}, the distance is returned in cells. Default is returning Distance Per Cell units.
* {{code|source}} - The id of the token to measure the distance from. Default is the current token.
* {{param|source}}The id 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}}
* {{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 tokens is returned.
** {{code|NO_GRID}} - The grid is ignored and straight line distance between the tokens is returned.
Line 29: Line 24:
** {{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}}.}}


|example=
|example=

Revision as of 16:58, 17 September 2019

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)
getDistanceToXY(x, y, units, source, metric)
getDistanceToXY(x, y, units, source, metric, pixels)

Parameters

  • x - {{{2}}}The X coordinate of the target grid cell.
  • y - {{{2}}}The Y coordinate of the target grid cell.
  • units - {{{2}}}If set to false(0), the distance is returned in cells. Default is returning Distance Per Cell units.
  • source - {{{2}}}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 strings
    • NO_GRID - The grid is ignored and straight line distance between the tokens 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 to true(1), the X and Y refer to pixels. If set to false(0), they refer to a cell. Default to false(0).

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.