getBar: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(New page: ==Function getBar== Returns the number padded in if it is an integer, otherwise the number is rounded down to the nearest smaller integer and that value is returned. ===Usage=== <source l...)
 
No edit summary
 
(24 intermediate revisions by 8 users not shown)
Line 1: Line 1:
==Function getBar==
{{MacroFunction
Returns the number padded in if it is an integer, otherwise the number is rounded down to the nearest smaller integer and that value is returned.
|name=getBar
|version=1.3b42
|description=Gets the value of the specified [[Token:bar|bar]] for the [[Current Token]]. The value returned is between 0 and 1 for 0% to 100% respectively.


===Usage===
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: result = floor(num)]
getBar(name)
</source>
getBar(name, tokenRef)
getBar(name, tokenRef, mapRef)
</syntaxhighlight>


===Examples===
'''Parameters'''
<source lang="mtmacro" line>
{{param|name|The name of the bar.}}
[r: floor(2)]
{{param|tokenRef|Either the token [[getSelected|{{code|id}}]] or [[getTokenName|Token Name]] of the token.
</source>
{{TrustedParameter}} }}
Returns 2.
{{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.}}


<source lang="mtmacro" line>
[r: floor(1.2)]
</source>
Returns 1.


<source lang="mtmacro" line>
|example=
[r: floor(-1.2)]
<syntaxhighlight lang="mtmacro" line>
</source>
[r: healthPct = getBar("Health") * 100]
Returns -2.
</syntaxhighlight>
 
|also=
{{func|isBarVisible}},
{{func|setBarVisible}},
{{func|setBar}}
 
|changes=
{{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]]

Latest revision as of 23:59, 10 May 2024

getBar() Function

Introduced in version 1.3b42
Gets the value of the specified bar for the Current Token. The value returned is between 0 and 1 for 0% to 100% respectively.

Usage

getBar(name)
getBar(name, tokenRef)
getBar(name, tokenRef, mapRef)

Parameters

  • name - The name of the bar.
  • tokenRef - Either the token id or Token Name of the 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.

Example

[r: healthPct = getBar("Health") * 100]

See Also

Version Changes

  • 1.5.7 - Added id and mapname parameter options.

Related Pages