setState: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Applied Template:MacroFunction)
No edit summary
 
(15 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{stub|Examples using new functionality.}}
{{MacroFunction
{{MacroFunction
|name=setState
|name=setState
|version=1.3b40
|description=
|description=
Sets the value of the [[Token:state|Token State]] on the [[Token:Current Token|Current Token]]. If The value is 0 then the [[Token:state|Token State]] is unset if it is non zero then it is set.
Sets the value of the [[State]] on [[Token]]. If The value is {{false}} then the [[State]] is unset if it is non-zero({{true}}) then it is set.


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: setState(name, value)]
setState(state, value)
</source>
setState(state, value, tokenRef)
setState(state, value, tokenRef, mapRef)
</syntaxhighlight>
'''Parameters'''
{{param|state|The name of the state to set on the token.}}
{{param|value|The value of the state to set, {{code|true}}({{code|1}}) or {{code|false}}({{code|0}}).}}
{{param|tokenRef|Either the token [[getSelected|{{code|id}}]] or [[getTokenName|Token Name]] of the token to have the [[State]] set.  Defaults to the [[Current Token]]. {{TrustedParameter}} }}
{{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=
To set the "Dead" [[Token:state|Token State]] on the [[Token:Current Token|Current Token]]
To set the "Dead" [[Token:state|Token State]] on the [[Current Token]]
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: setState("Dead", 1)]
[h: setState("Dead", 1)]
</source>
</syntaxhighlight>


To reset the "Dead" [[Token:state|Token State]] on the [[Token:Current Token|Current Token]]
To reset the "Dead" [[Token:state|Token State]] on the [[Current Token]]
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: setState("Dead", 0)]
[h: setState("Dead", 0)]
</source>
</syntaxhighlight>
 
|also=
[[State]],
[[getState|getState()]],
[[setAllStates|setAllStates()]]
 
|changes=
{{change|1.3b51|Added {{code|id}} parameter option.}}
{{change|1.5.4|Added {{code|mapname}} parameter option.}}
 
}}
}}
[[Category:State Function]]
[[Category:State Function]]
[[Category:Token Function]]

Latest revision as of 23:59, 11 May 2024

 This article is a stub, you can help the RPTools Wiki project by contributing content to expand this article.
 This article needs: Examples using new functionality.

setState() Function

Introduced in version 1.3b40
Sets the value of the State on Token. If The value is false(0) then the State is unset if it is non-zero(true(1)) then it is set.

Usage

setState(state, value)
setState(state, value, tokenRef)
setState(state, value, tokenRef, mapRef)

Parameters

  • state - The name of the state to set on the token.
  • value - The value of the state to set, true(1) or false(0).
  • tokenRef - Either the token id or Token Name of the token to have the State 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

To set the "Dead" Token State on the Current Token
[h: setState("Dead", 1)]

To reset the "Dead" Token State on the Current Token

[h: setState("Dead", 0)]

See Also

Version Changes

  • 1.3b51 - Added id parameter option.
  • 1.5.4 - Added mapname parameter option.