getDistance: Difference between revisions
m (Conversion script moved page GetDistance to getDistance: Converting page titles to lowercase) |
m (Text replacement - "source>" to "syntaxhighlight>") |
||
Line 9: | Line 9: | ||
<source lang="mtmacro" line> | <source lang="mtmacro" line> | ||
getDistance(target) | getDistance(target) | ||
</ | </syntaxhighlight> | ||
<source lang="mtmacro" line> | <source lang="mtmacro" line> | ||
getDistance(target, units) | getDistance(target, units) | ||
</ | </syntaxhighlight> | ||
<source lang="mtmacro" line> | <source lang="mtmacro" line> | ||
getDistance(target, units, source) | getDistance(target, units, source) | ||
</ | </syntaxhighlight> | ||
<source lang="mtmacro" line> | <source lang="mtmacro" line> | ||
getDistance(target, units, source, metric) | getDistance(target, units, source, metric) | ||
</ | </syntaxhighlight> | ||
'''Parameters''' | '''Parameters''' | ||
{{param|target|The id of the token that the distance is measured to.}} | {{param|target|The id of the token that the distance is measured to.}} | ||
Line 34: | Line 34: | ||
<source lang="mtmacro" line> | <source lang="mtmacro" line> | ||
[h: dist = getDistance("Altar")] | [h: dist = getDistance("Altar")] | ||
</ | </syntaxhighlight> | ||
To get the distance between the ''Altar'' and the ''Sacrifice'' in the number of squares or hexes. | To get the distance between the ''Altar'' and the ''Sacrifice'' in the number of squares or hexes. | ||
<source lang="mtmacro" line> | <source lang="mtmacro" line> | ||
[h: dist = getDistance("Altar", 0, "Sacrifice")] | [h: dist = getDistance("Altar", 0, "Sacrifice")] | ||
</ | </syntaxhighlight> | ||
To get the distance between the ''Altar'' and the ''Sacrifice'' in ''map distance'' units. | To get the distance between the ''Altar'' and the ''Sacrifice'' in ''map distance'' units. | ||
<source lang="mtmacro" line> | <source lang="mtmacro" line> | ||
[h: dist = getDistance("Altar", 1, "Sacrifice")] | [h: dist = getDistance("Altar", 1, "Sacrifice")] | ||
</ | </syntaxhighlight> | ||
To get the straight line distance between the ''Altar'' and the ''Sacrifice''. | To get the straight line distance between the ''Altar'' and the ''Sacrifice''. | ||
<source lang="mtmacro" line> | <source lang="mtmacro" line> | ||
[h: dist = getDistance("Altar", 1, "Sacrifice", "NO_GRID")] | [h: dist = getDistance("Altar", 1, "Sacrifice", "NO_GRID")] | ||
</ | </syntaxhighlight> | ||
|also= {{func|getDistanceToXY}} {{func|getTokens}} | |also= {{func|getDistanceToXY}} {{func|getTokens}} |
Revision as of 17:42, 14 March 2023
getDistance() Function
Note: This function can only be used in a Trusted Macro
Usage
<source lang="mtmacro" line> getDistance(target) </syntaxhighlight> <source lang="mtmacro" line> getDistance(target, units) </syntaxhighlight> <source lang="mtmacro" line> getDistance(target, units, source) </syntaxhighlight> <source lang="mtmacro" line> getDistance(target, units, source, metric) </syntaxhighlight> Parameters
target
- The id of the token that the distance is measured to.units
- If set tofalse
(0
), the distance is given in cells, otherwise the default is to return the distance in Distance Per Cell units.source
- The id of the token to measure the distance from, the 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 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
<source lang="mtmacro" line> [h: dist = getDistance("Altar")] </syntaxhighlight>
To get the distance between the Altar and the Sacrifice in the number of squares or hexes. <source lang="mtmacro" line> [h: dist = getDistance("Altar", 0, "Sacrifice")] </syntaxhighlight>
To get the distance between the Altar and the Sacrifice in map distance units. <source lang="mtmacro" line> [h: dist = getDistance("Altar", 1, "Sacrifice")] </syntaxhighlight>
To get the straight line distance between the Altar and the Sacrifice. <source lang="mtmacro" line> [h: dist = getDistance("Altar", 1, "Sacrifice", "NO_GRID")]
</syntaxhighlight>See Also
Version Changes
- 1.3b55 - Added the optional
metric
argument.