findToken: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 3: Line 3:
|trusted=true
|trusted=true
|version=1.3b48
|version=1.3b48
|description=Finds a [[Token:token|token]] on the current [[Map:map|map]] by the [[Token:token|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:token|token]] is not found then an empty string "" is returned.
|description=Finds a [[Token:token|token]] on the current [[Introduction to Mapping|map]] by the [[Token:token|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:token|token]] is not found then an empty string "" is returned.


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
findToken(name/ID)
findToken(name/ID)
findToken(name/ID,mapname)
findToken(name/ID,mapname)
</source>
</syntaxhighlight>
'''Parameters'''
'''Parameters'''
{{param|name/ID|Either the name of the token or the ID.}}
{{param|name/ID|Either the name of the token or the ID.}}
Line 16: Line 16:
|example=
|example=
Search for token on current map
Search for token on current map
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: id = findToken("Hero")]
[h: id = findToken("Hero")]
[if (id == "", "Token not found!", "Token found")]
[if (id == "", "Token not found!", "Token found")]
</source>
</syntaxhighlight>
Search for token on current map and then search the map named ''Stash'' if not found.
Search for token on current map and then search the map named ''Stash'' if not found.
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
<!-- Prompts for "TokenName" as it isn't already defined -->
<!-- Prompts for "TokenName" as it isn't already defined -->
[h: name = TokenName]
[h: name = TokenName]
Line 33: Line 33:
[r: name] found on map [r: getCurrentMapName()].
[r: name] found on map [r: getCurrentMapName()].
}]
}]
</source>
</syntaxhighlight>


}}
}}
[[Category:Find Function]][[Category:Token Function]]
[[Category:Find Function]][[Category:Token Function]]

Latest revision as of 17:01, 20 April 2023

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

findToken(name/ID)
findToken(name/ID,mapname)

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
[h: id = findToken("Hero")]
[if (id == "", "Token not found!", "Token found")]

Search for token on current map and then search the map named Stash if not found.

<!-- Prompts for "TokenName" as it isn't already defined -->
[h: name = TokenName]
[h: id = findToken(name)]
[r, if(id == ""), code: {
	Not on current map. Searching Stash.<br>
	<!-- Search on the map named "Stash" -->
	[h: id = findToken(name, "Stash")]
	[r: if(id == "", name + " not found!", name + " found in Stash")]
};{
	[r: name] found on map [r: getCurrentMapName()].
}]