setLibProperty: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(9 intermediate revisions by 3 users not shown)
Line 3: Line 3:
|version=1.3b48
|version=1.3b48
|description=
|description=
Sets the [[Token:token_property|Token Property]] on a [[Token:library_token|Library Token]]. if the name of the [[Token:library_token|Library Token]] is not specified then the [[Token:token_property|Token Property]] is set on the [[Token:library_token|Library Token]] that the macro is running from.
Sets the [[Token:token_property|Token Property]] on a [[Token:library_token|Library Token]]. If the name of the [[Token:library_token|Library Token]] is not specified then the [[Token:token_property|Token Property]] is set on the [[Token:library_token|Library Token]] that the macro is running from.


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
setLibProperty(name, value)
setLibProperty(name, value)
setLibProperty(name, value, libName)
setLibProperty(name, value, libName)
</source>
</syntaxhighlight>


|examples=
|examples=
Set a property on the [[Token:library_token|Library Token]] that the macro is running from.
Set a property on the [[Token:library_token|Library Token]] that the macro is running from.
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: setLibProperty("defaultStrength", 10)]
[h: setLibProperty("defaultStrength", 10)]
</source>
</syntaxhighlight>


Set a property on a specifig [[Token:library_token|Library Token]].
Set a property on a specific [[Token:library_token|Library Token]].
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: setLibProperty("defaultStrength", 10, "Lib:Character")]
[h: setLibProperty("defaultStrength", 10, "Lib:Character")]
</source>
</syntaxhighlight>


Known Bug: note that using setLibProperty during onCampaignLoad and not being on the map where the lib resides, will result in a duplicate of that lib on the current map!
{{Note|Using {{code|setLibProperty}} during {{code|onCampaignLoad}} and not being on the map where the library resides will result in a duplicate of that library token on the current map!  (Internally, MapTool has to change to the map containing the library token, make all of the changes to it, then change back to the current map.  Unfortunately, changes are cached until the {{code|onCampaignLoad}} macro is complete, so when the token changes are written out the macro is back on the current map and a new token is created!)}}
|changes=
'''Updated in 1.11:'''
MTscript functions for acting on library tokens have been modified to also work on [[MTscript_functions_related_to_Add-on_libraries|Add-on libraries]].
This modification allows the namespace of the add-on library to be used where the {{code|Lib:}} token name would normally appear.  For example,


<syntaxhighlight lang="mtmacro" line>
[h: setLibProperty("defaultStrength", 10, "com.myname.mt.my-first-addon")]
</syntaxhighlight>
The properties thus created belong to the add-on, but are stored in the campaign.  Removing the add-on will '''NOT''' delete this data.  (Currently (as of v1.14.3), the only way to erase this data is to create a new campaign.)
}}
}}
[[Category:Property Function]]
[[Category:Property Function]]
[[Category:Token Library Function]]
[[Category:Token Library Function]]
[[Category:Add-on Library Functions]]

Latest revision as of 23:59, 17 April 2024

setLibProperty() Function

Introduced in version 1.3b48
Sets the Token Property on a Library Token. If the name of the Library Token is not specified then the Token Property is set on the Library Token that the macro is running from.

Usage

setLibProperty(name, value)
setLibProperty(name, value, libName)

Examples

Set a property on the Library Token that the macro is running from.
[h: setLibProperty("defaultStrength", 10)]

Set a property on a specific Library Token.

[h: setLibProperty("defaultStrength", 10, "Lib:Character")]


Using setLibProperty during onCampaignLoad and not being on the map where the library resides will result in a duplicate of that library token on the current map! (Internally, MapTool has to change to the map containing the library token, make all of the changes to it, then change back to the current map. Unfortunately, changes are cached until the onCampaignLoad macro is complete, so when the token changes are written out the macro is back on the current map and a new token is created!)

Version Changes

Updated in 1.11: MTscript functions for acting on library tokens have been modified to also work on Add-on libraries. This modification allows the namespace of the add-on library to be used where the Lib: token name would normally appear. For example,

[h: setLibProperty("defaultStrength", 10, "com.myname.mt.my-first-addon")]

The properties thus created belong to the add-on, but are stored in the campaign. Removing the add-on will NOT delete this data. (Currently (as of v1.14.3), the only way to erase this data is to create a new campaign.)