js:MapTool.tokens: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(Created page with "{{Experimental}} {{MacroFunction |name=MapTool.tokens.getSelectedTokens |trusted=true |version=1.10.0 |description= Returns a javascript array containing the selected tokens....")
 
m (Corrected example)
 
(6 intermediate revisions by 4 users not shown)
Line 9: Line 9:


|usage=
|usage=
<source lang="javascript" line>
<syntaxhighlight lang="javascript" line>
let a = MapTool.tokens.getSelectedTokens();
let a = MapTool.tokens.getSelectedTokens();
</source>
</syntaxhighlight>


'''Parameters'''
'''Parameters'''
Line 26: Line 26:


|usage=
|usage=
<source lang="javascript" line>
<syntaxhighlight lang="javascript" line>
let token = MapTool.tokens.getSelected();
let token = MapTool.tokens.getSelected();
</source>
</syntaxhighlight>


'''Parameters'''
'''Parameters'''
Line 41: Line 41:
|version=1.10.0
|version=1.10.0
|description=
|description=
Returns the token specified.
Returns the token specified if it exists on any map.


|usage=
|usage=
<source lang="javascript" line>
<syntaxhighlight lang="javascript" line>
let token = MapTool.tokens.getTokenByID(tid);
let token = MapTool.tokens.getTokenByID(tid);
</source>
</syntaxhighlight>


'''Parameters'''
'''Parameters'''
Line 52: Line 52:
* {{code|return}} - The token with specified ID.   
* {{code|return}} - The token with specified ID.   
* {{code|throws}} - ArrayIndexOutOfBounds exception if the token cannot be found.
* {{code|throws}} - ArrayIndexOutOfBounds exception if the token cannot be found.
}}


{{MacroFunction
|name=MapTool.tokens.getMapTokenByID
|trusted=true
|version=1.14.0
|description=
Returns the token specified if it exists on the current map.


|usage=
<syntaxhighlight lang="javascript" line>
let token = MapTool.tokens.getMapTokenByID(tid);
</syntaxhighlight>


 
'''Parameters'''
 
* {{code|tid}} - String containing a valid token ID.
 
* {{code|return}} - The token with specified ID. 
* {{code|throws}} - ArrayIndexOutOfBounds exception if the token cannot be found.
}}
}}


Line 65: Line 77:
|version=1.10.0
|version=1.10.0
|description=
|description=
Returns a list of all tokens on all maps.
Returns a list of all tokens on a map.  If run from an untrusted namespace, only tokens owned by the calling player are returned.


|usage=
|usage=
<source lang="javascript" line>
<syntaxhighlight lang="javascript" line>
let token = MapTool.tokens.getMapTokens();
let token = MapTool.tokens.getMapTokens();
let token = MapTool.tokens.getMapTokens(name);
let token = MapTool.tokens.getMapTokens(name);
</source>
</syntaxhighlight>


'''Parameters'''
'''Parameters'''

Latest revision as of 23:59, 10 February 2024

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


MapTool.tokens.getSelectedTokens() Function

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

Introduced in version 1.10.0
Returns a javascript array containing the selected tokens.

Usage

let a = MapTool.tokens.getSelectedTokens();

Parameters

  • return - An array containing all selected tokens.


MapTool.tokens.getSelected() Function

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

Introduced in version 1.10.0
Like getSelectedTokens(), but only returns the first token.

Usage

let token = MapTool.tokens.getSelected();

Parameters

  • return - The first selected token, or null if no token is selected.


MapTool.tokens.getTokenByID() Function

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

Introduced in version 1.10.0
Returns the token specified if it exists on any map.

Usage

let token = MapTool.tokens.getTokenByID(tid);

Parameters

  • tid - String containing a valid token ID.
  • return - The token with specified ID.
  • throws - ArrayIndexOutOfBounds exception if the token cannot be found.


MapTool.tokens.getMapTokenByID() Function

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

Introduced in version 1.14.0
Returns the token specified if it exists on the current map.

Usage

let token = MapTool.tokens.getMapTokenByID(tid);

Parameters

  • tid - String containing a valid token ID.
  • return - The token with specified ID.
  • throws - ArrayIndexOutOfBounds exception if the token cannot be found.


MapTool.tokens.getMapTokens() Function

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

Introduced in version 1.10.0
Returns a list of all tokens on a map. If run from an untrusted namespace, only tokens owned by the calling player are returned.

Usage

let token = MapTool.tokens.getMapTokens();
let token = MapTool.tokens.getMapTokens(name);

Parameters

  • name - A string containing the name of the map to search for tokens.
  • return - A list containing all tokens on every map.

See Also

JS: MapTool.chat
JS: MapTool.clientInfo
JS: MapTool.tokens
JS: Tokens
JS: MTScript

js.eval()