getTokenRotation: Difference between revisions
Jump to navigation
Jump to search
m (Conversion script moved page GetTokenRotation to getTokenRotation: Converting page titles to lowercase) |
No edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
Line 12: | Line 12: | ||
|usage= | |usage= | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
getTokenRotation() | getTokenRotation() | ||
getTokenRotation( | getTokenRotation(tokenRef) | ||
getTokenRotation( | getTokenRotation(tokenRef, mapRef) | ||
</ | </syntaxhighlight> | ||
'''Parameters''' | '''Parameters''' | ||
{{param| | {{param|tokenRef|Either the token [[getSelected|{{code|id}}]] or [[getTokenName|Token Name]] of the token to retrieve the rotation angle. Defaults to the [[Current Token]].}}{{TrustedParameter}} | ||
{{param| | {{param|mapRef|The Name or ID of the map to find the token. Defaults to the current map.}} | ||
{{Note|Token IDs are unique, but Token Names can be duplicated. Using Token Name when more than one token has the same name can produce unexpected results.}} | |||
'''Result'''<br /> | '''Result'''<br /> | ||
Line 26: | Line 27: | ||
|example= | |example= | ||
Get the rotation for the four tokens shown below. | Get the rotation for the four tokens shown below. | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[h: switchToken("Mage")] | [h: switchToken("Mage")] | ||
[r: token.name] - [r: r = getTokenRotation()]<br> | [r: token.name] - [r: r = getTokenRotation()]<br> | ||
Line 34: | Line 35: | ||
[r: token.name] - [r: r = getTokenRotation()]<br> | [r: token.name] - [r: r = getTokenRotation()]<br> | ||
[h: switchToken("Troll")] | [h: switchToken("Troll")] | ||
[r: token.name] - [r: r = getTokenRotation()]</ | [r: token.name] - [r: r = getTokenRotation()]</syntaxhighlight> | ||
Returns: | Returns: | ||
[[File: | [[File:GetTokenRotation.png]] | ||
'''Relation to Token Facing''' | '''Relation to Token Facing''' | ||
Line 44: | Line 45: | ||
To convert from rotation to facing (or vice versa) these relations can be used: | To convert from rotation to facing (or vice versa) these relations can be used: | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
facing = -(rotation + 90) | facing = -(rotation + 90) | ||
</ | </syntaxhighlight> | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
rotation = -(facing + 90) | rotation = -(facing + 90) | ||
</ | </syntaxhighlight> | ||
|also= | |also= | ||
[[ | [[setTokenFacing]] | ||
|changes= | |changes= |
Latest revision as of 23:59, 14 May 2024
getTokenRotation() Function
• Introduced in version 1.5.0
Retrieves the angle of rotation for the token from the default position. Returned value is in degrees.
For Square, Round or Figure token types, this is the change in the facing indicator from the default of 0 degrees or no change in facing. Positive is CW and negative is CCW. Values will range from -270 to +89.
For Top Down tokens, this is the rotation of the token image itself from the default of 0 degrees.Usage
getTokenRotation()
getTokenRotation(tokenRef)
getTokenRotation(tokenRef, mapRef)
Parameters
tokenRef
- Either the tokenid
or Token Name of the token to retrieve the rotation angle. Defaults to the Current Token.Note: This parameter can only be used in a Trusted Macro.
mapRef
- The Name or ID of the map to find the token. Defaults to the current map.
Token IDs are unique, but Token Names can be duplicated. Using Token Name when more than one token has the same name can produce unexpected results.
Result
The function returns the token's rotation as a numeric value measured in degrees.
Example
Get the rotation for the four tokens shown below.
[h: switchToken("Mage")]
[r: token.name] - [r: r = getTokenRotation()]<br>
[h: switchToken("Elf")]
[r: token.name] - [r: r = getTokenRotation()]<br>
[h: switchToken("Hero")]
[r: token.name] - [r: r = getTokenRotation()]<br>
[h: switchToken("Troll")]
[r: token.name] - [r: r = getTokenRotation()]
Relation to Token Facing
When no facing has been set, getTokenFacing will return the blank string ""
but getTokenRotation will return 0. Consequently getTokenRotation does not require a check to ensure the result is usable for calculations.
To convert from rotation to facing (or vice versa) these relations can be used:
facing = -(rotation + 90)
rotation = -(facing + 90)
See Also
Version Changes
- 1.5.4 - Added
mapname
parameter option.