Calling a Lib:Token Property with another token's property?

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
alexjohnsonsays
Kobold
Posts: 4
Joined: Mon Jan 06, 2020 5:38 pm

Calling a Lib:Token Property with another token's property?

Post by alexjohnsonsays »

I'm not even sure where to start here. My party is going to go from map to map fairly often and I'd like their Tokens to automatically update Hit Points, Fatigue, etc across all maps from a Handouts Map which includes a list of PC's/NPC's.

Is there something you could put into a Property that pulls from some Lib:Token Property? Should I work on a Macro which updates the token with the appropriate Lib:Token stuff? Has this been done before so I can reference other peoples solutions?

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Calling a Lib:Token Property with another token's property?

Post by aliasmask »

It's possible, but complicated. I've been thinking of doing this myself so the token just references a table for all the token information. Basically, you have a big data structure will all the saved data and a way to check to update the current token. For example, you may write to the table the current token's id and name. Then going to another map it checks against that table and if the id is different, based on the name, then it'll update this token using the big data structure. Whenever there is a change in the token that data structure will have to be updated. Not sure how much overhead that will cause. You can get fancy and put flags in your data to tell you that only a branch of your data was changed and only change that one branch. With the new json.path fuctions there are lot more options for easy data manipulation.

But if you're new to all this then copy(or cut)/paste to new map is the easiest method. Using a macro to move the token to a new map is a bit safer than cut/paste.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Calling a Lib:Token Property with another token's property?

Post by wolph42 »

alternatively you could install the bag of tricks (link in sig) there are teleports on which you drag the tokens and they're transported to the other map or else there is a macro 'switch map' that does the same.

User avatar
Jason_c_o
Kobold
Posts: 6
Joined: Wed Mar 27, 2019 7:40 pm

Re: Calling a Lib:Token Property with another token's property?

Post by Jason_c_o »

I know this post is a few months old now but I have a solution to this.

First, make a Lib:Macros token and stick it on whatever map you want.
Give it the following two macros, UpdateLibrary and UpdateStats, respectively:

UpdateLibrary:

Code: Select all

[h: player = getPlayerName()]
[s,h: assert(isOwner(player), "You do not own this token.", 0)]
[h: sure = input("junkCheck|Are you sure you want to update this token's Library?|Click Okay to continue|LABEL|span=true")]
[s,h: assert(sure, "[<i>Update cancelled</i>]", 0)]
[h: propertyList = getPropertyNamesRaw()]
[h: libTokenName = concat("Lib:", token.name)]
[h,foreach(prop, propertyList, ""),CODE:{
	[h: setProp = getProperty(prop)]
	[h: setLibProperty(prop, setProp, libTokenName)]
}]
[s,r: "[<i>This token's Master has been updated</i>]"]
UpdateStats:

Code: Select all

[h: player = getPlayerName()]
[s,h: assert(isOwner(player), "You do not own this token.", 0)]
[h: sure = input("junkCheck|Are you sure you want to update this token's properties?|Click Okay to continue|LABEL|span=true")]
[s,h:assert(sure, "[<i>Update cancelled</i>]", 0)]
[h: propertyList = getPropertyNamesRaw()]
[h: libTokenName = concat("Lib:", token.name)]
[h,foreach(prop, propertyList, ""),CODE:{
	[h: setProp = getLibProperty(prop, libTokenName)]
	[h: setProperty(prop, setProp)]
}]
[s,r: "[<i>This token's properties have been updated</i>]"]
For both, uncheck "Editable by players"

Make your master tokens all Lib:CharName where CharName = the name of the copied tokens. (eg "Lib:Darius" and "Darius")

Stick these macros in your campaign macro window and set them to "Apply to selected tokens":

Code: Select all

[macro("UpdateLibrary@Lib:Macros"):""]
and

Code: Select all

[macro("UpdateStats@Lib:Macros"):""]
UpdateStats is what you want. It will grab all the properties from the Lib master token and update the current token. You must own the token.

UpdateLibrary is the other way around, so you can make quick edits without having to jump maps.

Both prompt in order to make sure there's no accidental clicks.

samll
Kobold
Posts: 1
Joined: Thu Nov 05, 2020 4:03 am

Re: Calling a Lib:Token Property with another token's property?

Post by samll »

I know this post is a few months old now but I have a solution to this.

First, make a Lib:Macros token and stick it on whatever map you want.
Give it the following two macros, UpdateLibrary and UpdateStats, respectively:

UpdateLibrary:

Code: Select all

[h: player = getPlayerName()]
[s,h: assert(isOwner(player), "You do not own this token.", 0)]
[h: sure = input("junkCheck|Are you sure you want to update this token's Library?|Click Okay to continue|LABEL|span=true")]
[s,h: assert(sure, "[<i>Update cancelled</i>]", 0)]
[h: propertyList = getPropertyNamesRaw()]
[h: libTokenName = concat("Lib:", token.name)]
[h,foreach(prop, propertyList, ""),CODE:{
	[h: setProp = getProperty(prop)]
	[h: setLibProperty(prop, setProp, libTokenName)]
}]
[s,r: "[<i>This token's Master has been updated</i>]"]
UpdateStats:

Code: Select all

[h: player = getPlayerName()]
[s,h: assert(isOwner(player), "You do not own this token.", 0)]
[h: sure = input("junkCheck|Are you sure you want to update this token's properties?|Click Okay to continue|LABEL|span=true")]
[s,h:assert(sure, "[<i>Update cancelled</i>]", 0)]
[h: propertyList = getPropertyNamesRaw()]
[h: libTokenName = concat("Lib:", token.name)]
[h,foreach(prop, propertyList, ""),CODE:{
	[h: setProp = getLibProperty(prop, libTokenName)]
	[h: setProperty(prop, setProp)]
}]
[s,r: "[<i>This token's properties have been updated</i>]"]
For both, uncheck "Editable by players"

Make your master tokens all Lib:CharName where CharName = the name of the copied tokens. (eg "Lib:Darius" and "Darius")

Stick these macros in your campaign macro window and set them to "Apply to selected tokens":

Code: Select all

[macro("UpdateLibrary@Lib:Macros"):""]
and

Code: Select all

[macro("UpdateStats@Lib:Macros"):""]
UpdateStats is what you want. It will grab all the properties from the Lib master token and update the current token. You must own the token.

UpdateLibrary is the other way around, so you can make quick edits without having to jump maps.

Both prompt in order to make sure there's no accidental clicks.
I've tried following your solution but in the end, only get an unknown error
what version of MapToll did you use?
Hi there

Post Reply

Return to “Macros”