js:Token: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Added missing parameter to isOwner())
m (Fixed capitalization and references to other pages)
Line 1: Line 1:
{{Experimental}}
{{Experimental}}
Within the javascript environment used by {{code|js.eval}}, Tokens are represented by the {{code|Token}} class.  The token class cannot be directly instantiated, but tokens can be found from the {{code|MapTool}} top level name.
Within the JavaScript environment used by {{code|js.eval}}, ie. the one that executes within GraalVM and NOT the one used by {{func|dialog5}} or {{func|frame5}}, tokens are represented by the {{code|Token}} class.  The {{code|Token}} class cannot be directly instantiated, but tokens can be found from the {{code|MapTool}} top level name.


{{MacroFunction
{{MacroFunction
Line 174: Line 174:
</syntaxhighlight>
</syntaxhighlight>


* {{param|playerName|a string representing the player name to check for.  See {{func|isOwner}} for details, but note that this function takes a parameter and the MTscript one does not.}}
* {{param|playerName|a string representing the player name to check for.  See {{func|isOwner}} for details, but note that this function requires a single parameter and the MTscript one does not.}}


Ownership is determined thusly:
Ownership is determined thusly:
* this call is running in a '''trusted''' context — returns {{code|true}}.
* This call is running in a '''trusted''' context — returns {{code|true}}.
* this token has '''ALL''' players as owners — returns {{code|true}}.
* This token has '''ALL''' players as owners — returns {{code|true}}.
* this token has the given player name in the list of owners — returns {{code|true}}.
* This token has the given player name in the list of owners — returns {{code|true}}.
* All other conditions return {{code|false}}.
* All other conditions return {{code|false}}.
}}
}}

Revision as of 02:21, 3 July 2023

 This article describes a feature or macro function that is experimental and may be subject to change.

Within the JavaScript environment used by js.eval, ie. the one that executes within GraalVM and NOT the one used by dialog5() or frame5(), tokens are represented by the Token class. The Token class cannot be directly instantiated, but tokens can be found from the MapTool top level name.


token.getNotes() Function

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

Introduced in version 1.10.0
Returns the Notes field of the token. No processing of the content is performed (this means Notes entered as HTNL will return the HTML content, for example).

Usage

token.getNotes();


token.setNotes() Function

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

Introduced in version 1.10.0
Sets the Notes field of the token.

Usage

token.setNotes(newNotes);
  • newNotes - a string representing the new Notes of the token. See getNotes() for details.


token.getName() Function

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

Introduced in version 1.10.0
Returns the name of the token.

Usage

token.getName();


token.setName() Function

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

Introduced in version 1.10.0
Sets the name of the token.

Usage

token.setName(newName);
  • newName - a string representing the new name of the token. See setName() for details.


token.hasSight() Function

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

Introduced in version 1.10.0
Returns true if sight is enabled for the token.

Usage

token.hasSight();


token.getId() Function

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

Introduced in version 1.10.0
Returns the MapTool token ID of the token.

Usage

token.getId();


token.getProperty() Function

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

Introduced in version 1.10.0
Returns the value of the given token property.

Usage

token.getProperty(property);
  • property - a string representing the name of the property on the token. See getProperty() for details.


token.setProperty() Function

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

Introduced in version 1.10.0
Sets the value of the token property.

Usage

token.setProperty(property, newValue);
  • property - a string representing the name of the property on the token. See setProperty() for details.
  • newValue - the new value to store into the token property.


token.getX() Function

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

Introduced in version 1.10.0
Returns the X position of the token.

Usage

token.getX();

See getTokenX() for details.


token.getY() Function

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

Introduced in version 1.10.0
Returns the Y position of the token.

Usage

token.getY();

See getTokenY() for details.


token.setX() Function

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

Introduced in version 1.10.0
Sets the X position of the token.

Usage

token.setX(newX);


token.setY() Function

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

Introduced in version 1.10.0
Sets the Y position of the token.

Usage

token.setY(newY);


token.isOwner() Function

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

Introduced in version 1.10.0
Returns true if the given player is an owner.

Usage

token.isOwner(playerName);
  • playerName - a string representing the player name to check for. See isOwner() for details, but note that this function requires a single parameter and the MTscript one does not.

Ownership is determined thusly:

  • This call is running in a trusted context — returns true.
  • This token has ALL players as owners — returns true.
  • This token has the given player name in the list of owners — returns true.
  • All other conditions return false.


See Also

JS: MapTool