getDistanceToXY: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
mNo edit summary
(Updated for b55 changes and created examples for the function, added see also)
Line 15: Line 15:
<source lang="mtmacro" line>
<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)
</source>
</source>
'''Parameters'''
'''Parameters'''
Line 21: Line 24:
* {{code|units}} - If set to {{code|false}}({{code|0}}) the distance is returned in cells. Default is returning Distance Per Cell units.
* {{code|units}} - If set to {{code|false}}({{code|0}}) 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.
* {{code|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}}
** {{code|NO_GRID}} - The grid is ignored and straight line distance between the tokens is returned.
** {{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|MANHATTAN}} - Diagonal movement costs 2 (Square grid only).
** {{code|NO_DIAGONALS}} - No diagonal movement is allowed (Square grid only).


|example=
To get the distance from the current token to 10,10.
<source lang="mtmacro" line>
[h: dist = getDistanceToXY(10, 10)]
</source>
To get the distance between the ''Altar'' and 10, 10 in the number of squares or hexes.
<source lang="mtmacro" line>
[h: dist = getDistance(10, 10, 0, "Altar")]
</source>
To get the distance between the ''Altar'' and 10, 10 in ''map distance'' units.
<source lang="mtmacro" line>
[h: dist = getDistance(10, 10, 1, "Altar")]
</source>
To get the straight line distance between the ''Altar'' and 10, 10.
<source lang="mtmacro" line>
[h: dist = getDistance(10, 10, 1, "Altar", "NO_GRID")]
</source>
|also=
{{func|getDistance}} {{func|getTokens}}
|changes=
{{code|b55}} - added the optional metric argument.
}}
}}
}}
[[Category:Distance Function]]
[[Category:Distance Function]]

Revision as of 06:56, 14 April 2009

 This article is a stub, you can help the RPTools Wiki project by contributing content to expand this article.

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)

Parameters

  • x - The X coordinate of the target grid cell.
  • y - The Y coordinate of the target grid cell.
  • units - If set to false(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 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).

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 = getDistance(10, 10, 0, "Altar")]

To get the distance between the Altar and 10, 10 in map distance units.

[h: dist = getDistance(10, 10, 1, "Altar")]

To get the straight line distance between the Altar and 10, 10.

[h: dist = getDistance(10, 10, 1, "Altar", "NO_GRID")]

See Also

Version Changes

b55 - added the optional metric argument.

}}