setBarVisible: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
m (Added link to GitHub issue)
 
(8 intermediate revisions by 5 users not shown)
Line 6: Line 6:


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
setBarVisible(name, value)
setBarVisible(name, value)
setBarVisible(name, value, id)
setBarVisible(name, value, tokenRef)
setBarVisible(name, value, id, mapname)
setBarVisible(name, value, tokenRef, mapRef)
</source>
</syntaxhighlight>


'''Parameters'''
'''Parameters'''
{{param|bar|A string that contains the name of the bar that has its visibility set.}}
{{param|bar|A string that contains the name of the bar that has its visibility set.}}
{{param|value|The visibility value of the bar, either 0 or 1.}}
{{param|value|The visibility value of the bar, either 0 or 1.  Using a value of {{code|0}} causes the ''value'' of the bar to also be set to {{code|0}}!  This means that later setting the visibility back to {{code|1}} will not show the bar since it's now empty.  '''Rule of Thumb:''' when using {{code|setBarVisible()}} to turn on visibility, always follow it immediately with a call to {{func|setBar}}.  See this [https://github.com/RPTools/maptool/issues/2326 GitHub issue] for more discussion.}}
{{param|id|The token {{code|id}} of the token which has its bar visibility set, defaults to the [[Current Token]]. {{TrustedParameter}} }}
{{param|tokenRef|Either the token [[getSelected|{{code|id}}]] or [[getTokenName|Token Name]] of the token which has its bar visibility set, defaults to the [[Current Token]]. {{TrustedParameter}} }}
{{param|mapname|The name of the map to find the token.  Defaults to the current map.}}
{{param|mapRef|The Name or ID of the map to find the token.  Defaults to the current map.}}
{{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.}}


|examples=
|examples=
Make "health" [[Token:bar|bar]] for the [[Current Token]] visible.
Make "health" [[Token:bar|bar]] for the [[Current Token]] visible.
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: setBarVisible("Health", 1)]
[h: setBarVisible("Health", 1)]
</source>
[h: setBar("Health", 0.75)]<!-- sets the bar to be 75% full -->
</syntaxhighlight>


Hide "health" [[Token:bar|bar]] for the [[Current Token]].
Hide "health" [[Token:bar|bar]] for the [[Current Token]].
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: setBarVisible("Health", 0)]
[h: setBarVisible("Health", 0)]
</source>
</syntaxhighlight>
 
|also=
{{func|isBarVisible}},
{{func|getBar}},
{{func|setBar}}


|changes=
|changes=
{{change|1.5.7|Added {{code|id}} and {{code|mapname}} parameter option.}}
{{change|1.5.7|Added {{code|id}} and {{code|mapname}} parameter options.}}
}}
==Related Pages==


* [[HP and Health Bars]]
* [[bar.name|The <code>bar.name</code> special variable]]


}}
[[Category:Bar Function]]
[[Category:Bar Function]]

Latest revision as of 01:23, 25 November 2024

setBarVisible() Function

Introduced in version 1.3b46
Sets if the specified bar for the Current Token is visible or not. If the value is non zero then the bar is visible, if it is 0 it is not visible.

Usage

setBarVisible(name, value)
setBarVisible(name, value, tokenRef)
setBarVisible(name, value, tokenRef, mapRef)

Parameters

  • bar - A string that contains the name of the bar that has its visibility set.
  • value - The visibility value of the bar, either 0 or 1. Using a value of 0 causes the value of the bar to also be set to 0! This means that later setting the visibility back to 1 will not show the bar since it's now empty. Rule of Thumb: when using setBarVisible() to turn on visibility, always follow it immediately with a call to setBar(). See this GitHub issue for more discussion.
  • tokenRef - Either the token id or Token Name of the token which has its bar visibility set, defaults to the Current Token.

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

  • mapRef - The Name or ID of the map to find the token. Defaults to the current map.
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.

Examples

Make "health" bar for the Current Token visible.
[h: setBarVisible("Health", 1)]
[h: setBar("Health", 0.75)]<!-- sets the bar to be 75% full -->

Hide "health" bar for the Current Token.

[h: setBarVisible("Health", 0)]

See Also

Version Changes

  • 1.5.7 - Added id and mapname parameter options.

Related Pages