getTokenRotation: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(9 intermediate revisions by 4 users not shown)
Line 7: Line 7:
Retrieves the angle of rotation for the token from the default position.  Returned value is in degrees.
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 +85.
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.
For Top Down tokens, this is the rotation of the token image itself from the default of 0 degrees.


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
getTokenRotation()
getTokenRotation()
getTokenRotation(id)
getTokenRotation(id)
getTokenRotation(id, mapname)
getTokenRotation(id, mapname)
</source>
</syntaxhighlight>


'''Parameters'''
'''Parameters'''
Line 26: Line 26:
|example=
|example=
Get the rotation for the four tokens shown below.
Get the rotation for the four tokens shown below.
<source lang="mtmacro" line>
<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 34:
[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()]</source>
[r: token.name] - [r: r = getTokenRotation()]</syntaxhighlight>
Returns:
Returns:
[[File:getTokenRotation.png]]
[[File:GetTokenRotation.png]]


'''Relation to Token Facing'''
'''Relation to Token Facing'''


When the facing is defined, the relation between token's rotation and the token's facing can be expressed as
When no facing has been set, [[getTokenFacing]] will return the blank string {{code|""}} but getTokenRotation will return 0. Consequently getTokenRotation does not require a check to ensure the result is usable for calculations.


<source lang="mtmacro" line>
To convert from rotation to facing (or vice versa) these relations can be used:
 
<syntaxhighlight lang="mtmacro" line>
facing = -(rotation + 90)
</syntaxhighlight>
<syntaxhighlight lang="mtmacro" line>
rotation = -(facing + 90)
rotation = -(facing + 90)
</source>
</syntaxhighlight>
 
When no facing has been set, [[getTokenFacing]] will return the blank string `""` but `getTokenRotation` will return 0.


|also=
|also=
[[getTokenFacing]]
[[setTokenFacing]]


|changes=
|changes=

Latest revision as of 22:22, 5 June 2023

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(id)
getTokenRotation(id, mapname)

Parameters

  • id - The token id of the token to retrieve the rotation angle. 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.

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()]

Returns:

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.