getTokenFacing: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
m (Text replacement - "<source" to "<syntaxhighlight")
 
(4 intermediate revisions by 2 users not shown)
Line 8: Line 8:


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
getTokenFacing()
getTokenFacing()
getTokenFacing(id)
getTokenFacing(id)
getTokenFacing(id, mapname)
getTokenFacing(id, mapname)
</source>
</syntaxhighlight>
'''Parameters'''
'''Parameters'''
{{param|id|The id of the token to get the facing from, defaults to the current token.}}{{TrustedParameter}}
{{param|id|The id of the token to get the facing from, defaults to the current token.}}{{TrustedParameter}}
Line 21: Line 21:


|example=
|example=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: switchToken("Mage")]
[h: switchToken("Mage")]
[r: token.name]: [r: r = getTokenFacing()]<br>
[r: token.name]: [r: r = getTokenFacing()]<br>
Line 30: Line 30:
[h: switchToken("Troll")]
[h: switchToken("Troll")]
[r: token.name]: [r: r = getTokenFacing()]
[r: token.name]: [r: r = getTokenFacing()]
</source>
</syntaxhighlight>
'''Returns:'''<br />
'''Returns:'''<br />
[[File:getTokenFacing.png]]
[[File:GetTokenFacing.png]]
|also=
|also=
[[setTokenFacing]]<br />[[getTokenRotation]]
[[setTokenFacing]]<br />[[getTokenRotation]]

Latest revision as of 21:03, 14 March 2023

getTokenFacing() Function

Introduced in version 1.3b51
Gets the facing angle for the specified or current token. Values will range from -179 to +180. Default facing is -90 degrees or down, 0 degrees is to the right, +90 degrees is up, +180 degrees is to the left. The jump in the value range is the difference between "exactly left" (+180) and "almost exactly left, but tilted 1 degree down" (-179).
Note that math.atan2_r can be used to calculate facing from a direction given in two coordinate pairs.

Usage

getTokenFacing()
getTokenFacing(id)
getTokenFacing(id, mapname)

Parameters

  • id - The id of the token to get the facing from, defaults to the current token.

     Note: This parameter can only be used in a Trusted Macro

  • mapname - The name of the map to find the token. Defaults to the current map.

Returns The angle in degrees or "" if no facing has been set

Example

[h: switchToken("Mage")]
[r: token.name]: [r: r = getTokenFacing()]<br>
[h: switchToken("Elf")]
[r: token.name]: [r: r = getTokenFacing()]<br>
[h: switchToken("Hero")]
[r: token.name]: [r: r = getTokenFacing()]<br>
[h: switchToken("Troll")]
[r: token.name]: [r: r = getTokenFacing()]

Returns:

See Also

Version Changes

  • 1.5.4 - Added mapname parameter option.