isVisible: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(added example)
No edit summary
 
(7 intermediate revisions by 4 users not shown)
Line 3: Line 3:
|version=1.3b69
|version=1.3b69
|description=
|description=
check whether a point on the map is visible from a token or not.
Check whether a point on the map is visible from a token or not.
It returns 1 is the token is visible, 0 otherwise. This vision is based off of the impersonated token.
It returns 1 if the token is visible, 0 otherwise. This vision is based off of the impersonated token.
|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
isVisible(x,y)
isVisible(x,y)
</source>
isVisible(x,y,tokenRef)
<source lang="mtmacro" line>
</syntaxhighlight>
isVisible(x,y,id)
</source>
'''Parameter'''
'''Parameter'''
{{param|x|Then tokens x coordinate. Always in map units, not grid .}}
{{param|x|Then tokens x coordinate. Always in map units, not grid .}}
{{param|y|Then tokens x coordinate. Always in map units, not grid .}}
{{param|y|Then tokens x coordinate. Always in map units, not grid .}}
{{param|id|The check for visibility is performed from token {{code|id}}.  {{TrustedParameter}}
{{param|tokenRef|The check for visibility is performed from either the token [[getSelected|{{code|id}}]] or [[getTokenName|Token Name]] of the token.  {{TrustedParameter}}
}}
}}
{{Note|Token IDs are unique, but Token Names can be duplicated. Using Token Name when more than one token has the same name can produce unexpected results.}}


|example=
|example=
A simple example for testing out {{code|isVisible()}}. Drop the default tokens "Hero" and "Troll" on a map. Make sure "Hero" has sight (make him PC or set sight manually). You can then execute the following code as a campaign macro to check if the Hero can see the Troll.
A simple example for testing out {{code|isVisible()}}. Drop the default tokens "Hero" and "Troll" on a map. Make sure "Hero" has sight (make him PC or set sight manually). You can then execute the following code as a campaign macro to check if the Hero can see the Troll.
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
<!-- lets check if token1 can see token2 -->
<!-- lets check if token1 can see token2 -->
[h: token1 = "Hero"]
[h: token1 = "Hero"]
Line 37: Line 36:
<!-- and final the check for visiblity -->
<!-- and final the check for visiblity -->
[r:getName(id1)] <b>[r, if(isVisible(x,y, id1)): "can"; "cannot"]</b> see [r:getName(id2)].
[r:getName(id1)] <b>[r, if(isVisible(x,y, id1)): "can"; "cannot"]</b> see [r:getName(id2)].
</source>
</syntaxhighlight>


|also=
[[canSeeToken|canSeeToken()]]


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

Latest revision as of 23:59, 17 May 2024

isVisible() Function

Introduced in version 1.3b69
Check whether a point on the map is visible from a token or not. It returns 1 if the token is visible, 0 otherwise. This vision is based off of the impersonated token.

Usage

isVisible(x,y)
isVisible(x,y,tokenRef)

Parameter

  • x - Then tokens x coordinate. Always in map units, not grid .
  • y - Then tokens x coordinate. Always in map units, not grid .
  • tokenRef - The check for visibility is performed from either the token id or Token Name of the token.

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


Token IDs are unique, but Token Names can be duplicated. Using Token Name when more than one token has the same name can produce unexpected results.

Example

A simple example for testing out isVisible(). Drop the default tokens "Hero" and "Troll" on a map. Make sure "Hero" has sight (make him PC or set sight manually). You can then execute the following code as a campaign macro to check if the Hero can see the Troll.
<!-- lets check if token1 can see token2 -->
[h: token1 = "Hero"]
[h: id1 = findToken(token1)]

[h: token2 = "Troll"]
[h: id2 = findToken(token2)]

<!-- get the map coordinates of token2 -->
<!-- i want to check if the center of the occupied cell can be seen -->
<!-- getTokenX/Y retrieves the top-left corner, so -->
<!-- in a 50 pixel grid the center is offset by 25 pixel -->
[h: x = getTokenX(1, id2)+25]
[h: y = getTokenY(1, id2)+25]

<!-- and final the check for visiblity -->
[r:getName(id1)] <b>[r, if(isVisible(x,y, id1)): "can"; "cannot"]</b> see [r:getName(id2)].

See Also