getProperty: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(21 intermediate revisions by 9 users not shown)
Line 1: Line 1:
==Function getProperty==
{{stub|Examples of usage.}}
{{MacroFunction
|name=getProperty
|version=1.3b48
|description=
Returns the value of a [[Token Property]] on a [[Token]]. 
If the [[Token Property]] is empty ({{code|NULL}}) or not defined, an empty string ({{code|""}}) is returned.
|usage=
<syntaxhighlight lang="mtmacro" line>
getProperty(property)
getProperty(property, tokenRef)
getProperty(property, tokenRef, mapname)
</syntaxhighlight>


Returns the value of a [[Token:property| token property]] of the [[Token:Current Token|Current Token]]. If the [[Token:property| token property]] contains nothing then an empty string ("") is returned. This function will not return the default value for a property if it is empty.
'''Parameter'''
{{param|property|The property that has its value returned. For referencing the literal name of the property (for instance, if you wish to get the property ''Constitution'' configured in Campaign Properties), enclose the property name in quotes. If using a variable whose ''value ''is the name of the property, do not enclose the variable name in quotes.}}
{{param|tokenRef|Either the token [[getSelected|{{code|id}}]] or [[getTokenName|Token Name]] of the token, defaults to the [[Current Token]]. {{TrustedParameter}} }}
{{param|mapname|The name 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>
 
[h: val = getProperty(name)]
|example=
</source>
Getting a property using the literal property name.
<syntaxhighlight lang="mtmacro" line>
The value of property 'Strength' is [r: getProperty("Strength")].
</syntaxhighlight>
 
This will output the following if '''Strength''' has the value '''18''':
The value of property 'Strength' is 18.
 
Getting a property using a variable.
<syntaxhighlight lang="mtmacro" line>
[h:desiredProperty = "Constitution"]
The value of property 'Constitution' is [r: getProperty(desiredProperty)].
</syntaxhighlight>
This will output the following if '''Constitution''' has the value '''12''':
  The value of property 'Constitution' is 12.
|also=
[[setProperty|setProperty()]],
[[resetProperty|resetProperty()]],
[[isPropertyEmpty|isPropertyEmpty()]]
 
|changes=
{{change|1.3b51|Added {{code|id}} parameter option.}}
{{change|1.3b51|Changed to return the default value if the property has no value.}}
{{change|1.5.4|Added {{code|mapname}} parameter option.}}
 
}}
[[Category:Token Function]][[Category:Property Function]]

Latest revision as of 18:14, 10 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 of usage.

getProperty() Function

Introduced in version 1.3b48
Returns the value of a Token Property on a Token. If the Token Property is empty (NULL) or not defined, an empty string ("") is returned.

Usage

getProperty(property)
getProperty(property, tokenRef)
getProperty(property, tokenRef, mapname)

Parameter

  • property - The property that has its value returned. For referencing the literal name of the property (for instance, if you wish to get the property Constitution configured in Campaign Properties), enclose the property name in quotes. If using a variable whose value is the name of the property, do not enclose the variable name in quotes.
  • tokenRef - Either the token id or Token Name of the token, defaults to the Current Token.

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

  • mapname - The name 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

Getting a property using the literal property name.
The value of property 'Strength' is [r: getProperty("Strength")].

This will output the following if Strength has the value 18:

The value of property 'Strength' is 18.

Getting a property using a variable.

[h:desiredProperty = "Constitution"]
The value of property 'Constitution' is [r: getProperty(desiredProperty)].

This will output the following if Constitution has the value 12:

The value of property 'Constitution' is 12.

See Also

Version Changes

  • 1.3b51 - Added id parameter option.
  • 1.3b51 - Changed to return the default value if the property has no value.
  • 1.5.4 - Added mapname parameter option.