findToken

From RPTools Wiki
Revision as of 17:24, 14 March 2023 by Taustin (talk | contribs) (Text replacement - "<source" to "<syntaxhighlight")
Jump to navigation Jump to search

findToken() Function

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

Introduced in version 1.3b48
Finds a token on the current map by the token name, GM name, or ID and returns its id. If the optional mapname parameter is supplied that map will be searched instead. If the token is not found then an empty string "" is returned.

Usage

<syntaxhighlight lang="mtmacro" line> findToken(name/ID) findToken(name/ID,mapname) </source> Parameters

  • name/ID - Either the name of the token or the ID.
  • mapname - Optional name of the map to search for the token on.

Example

Search for token on current map

<syntaxhighlight lang="mtmacro" line> [h: id = findToken("Hero")] [if (id == "", "Token not found!", "Token found")] </source> Search for token on current map and then search the map named Stash if not found. <syntaxhighlight lang="mtmacro" line> [h: name = TokenName] [h: id = findToken(name)] [r, if(id == ""), code: { Not on current map. Searching Stash.
[h: id = findToken(name, "Stash")] [r: if(id == "", name + " not found!", name + " found in Stash")] };{ [r: name] found on map [r: getCurrentMapName()]. }]

</source>