setProperty: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(6 intermediate revisions by 4 users not shown)
Line 8: Line 8:


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
setProperty(property, value)
setProperty(property, value)
</source>
setProperty(property, value, tokenRef)
<source lang="mtmacro" line>
setProperty(property, value, tokenRef, mapRef)
setProperty(property, value, id)
</syntaxhighlight>
</source>
'''Parameters'''
'''Parameters'''
{{param|property|A string containing the name of the property that has its value set.}}
{{param|property|A string containing the name of the property that has its value set.}}
{{param|value|The value that the property is set to.}}
{{param|value|The value that the property is set to.}}
{{param|id|The token {{code|id}} of the token which has its property 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 property 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=
Sets a property named {{code|Health}} to the value of {{code|10}} on the [[Current Token]].
Sets a property named {{code|Health}} to the value of {{code|10}} on the [[Current Token]].
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: setProperty("Health", 10)]
[h: setProperty("Health", 10)]
</source>
</syntaxhighlight>


Sets a property named {{code|Fatigue}} to the value of {{code|5}} on the selected token.
Sets a property named {{code|Fatigue}} to the value of {{code|5}} on the selected token.
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: setProperty("Fatigue", 5, getSelected())]
[h: setProperty("Fatigue", 5, getSelected())]
</source>
</syntaxhighlight>


Sets a property named {{code|Strength}} to the value of {{code|20}} on the selected token using variables.
Sets a property named {{code|Strength}} to the value of {{code|20}} on the selected token using variables.
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: Property = "Strength"]
[h: Property = "Strength"]
[h: Value = 20]
[h: Value = 20]
[h: ID = getSelected()]
[h: ID = getSelected()]
[h: setProperty(Property, Value, ID)]
[h: setProperty(Property, Value, ID)]
</source>
</syntaxhighlight>


|also=
|also=
Line 45: Line 47:
|changes=
|changes=
{{change|1.3b51|Added {{code|id}} parameter option.}}
{{change|1.3b51|Added {{code|id}} parameter option.}}
{{change|1.5.4|Added {{code|mapname}} parameter option.}}


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

Latest revision as of 23:59, 11 May 2024

setProperty() Function

Introduced in version 1.3b48
Sets the value of a Token Property on the Current Token (unless trusted, in which case a Token ID can be supplied to indicate which token is to be affected). Note that if there is not already an existing property by the name listed in the macro, setProperty will create a new Token Property with that name. Any created Property will not be visible in the Properties tab of the Edit Token window but can still be used like normal. It's value can be retrieved with the getProperty command.

Usage

setProperty(property, value)
setProperty(property, value, tokenRef)
setProperty(property, value, tokenRef, mapRef)

Parameters

  • property - A string containing the name of the property that has its value set.
  • value - The value that the property is set to.
  • tokenRef - Either the token id or Token Name of the token which has its property 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

Sets a property named Health to the value of 10 on the Current Token.
[h: setProperty("Health", 10)]

Sets a property named Fatigue to the value of 5 on the selected token.

[h: setProperty("Fatigue", 5, getSelected())]

Sets a property named Strength to the value of 20 on the selected token using variables.

[h: Property = "Strength"]
[h: Value = 20]
[h: ID = getSelected()]
[h: setProperty(Property, Value, ID)]

See Also

Version Changes

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