Macro somehow editing lib token properties without being told to.

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
Post Reply
JawareBloodriver
Kobold
Posts: 11
Joined: Wed Oct 03, 2018 10:19 pm

Macro somehow editing lib token properties without being told to.

Post by JawareBloodriver »

So I've hit a snag in my endeavors of making a fairly large net of interconnected macros.

the long story short, Ive made a Lib token that holds information regarding individual characters.

it holds it all in one Token property. an array. their are two arrays inside of said 'parent' array. One for Active players, and Inactive players.
the idea is to have all the active players easily accessible without me having to edit a list every time someone decides not to show, or sidelines a character. etc. I can just click a button and give all active players XP and Fate. etc. Its pretty convenient.

Not sure if its pert ant information or not, but the macro that i am working on at the moment deals with a part of the character. The jsons that i am working with are inception levels of information. Total Character roster -> active/Inactive rosters -> Individual character jsonObjects -> and then each of some dozen or so nuggets of info like XP, Date created, Wallet, Etc.

Now. On to my issue.

I have a macro thats function at this moment is to extract an object out of the character object so i can modify it. No problems there. Ive done it some 15 or 20 times to modify other pieces of the property.

BUT. For some reason, that i can neither understand, or track, or anything. it is randomly overighting the total roster. Which doesnt make any sense. seeing as how nothing is saving to a token property anywere in the macro. its just pulling from it. but for whatever the reason, its just deleting the Lib token peoperty to blank. Ive done everything within my power to try and fix it. or at the very least figure out how or why its happening. but im just pulling blanks.

the code that is doing it is LITERALLY copy pasted from other macros that don't do this. i dont understand what is happening.

any thoughts or ideas?

Code: Select all

<!--
==============================
Macro is called from a either, A) macrolink in from the individual character frame.
or B) just a floating macro. used while game is in session.

it is used to add a new Test to the character or to modify a test already present.
==============================
 -->

<!-- Step 1. Get all relevant Variables. save them for future macro use. -->

[h: CharacterList = ""]
[h: TotalRoster =  getLibProperty("CharacterList", "Lib:Rewards") ]
[h: ActiveRoster = json.get(TotalRoster, 0)]
[h: UnactiveRoster = json.get(TotalRoster, 1)]

<!--========================================================================================================-->
[FOREACH(Character, ActiveRoster, "<br>") , CODE:
{
[h: count=roll.count]
[h: CharSlot = json.get(ActiveRoster, count)]
[h: CharName = json.get(CharSlot, "Character")]
[h: CharacterList = listAppend(CharacterList, CharName)]
} ]

[h: Pause("CharacterList")]

<!--========================================================================================================-->
the code snippet that is doing it is between step 1 comment line and the next comment line of the bar of equal signs.

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Macro somehow editing lib token properties without being told to.

Post by Full Bleed »

JawareBloodriver wrote:
Sun Oct 06, 2019 8:12 am
any thoughts or ideas?

Code: Select all

<!--
==============================
Macro is called from a either, A) macrolink in from the individual character frame.
or B) just a floating macro. used while game is in session.

it is used to add a new Test to the character or to modify a test already present.
==============================
 -->

<!-- Step 1. Get all relevant Variables. save them for future macro use. -->

[h: CharacterList = ""]
[h: TotalRoster =  getLibProperty("CharacterList", "Lib:Rewards") ]
[h: ActiveRoster = json.get(TotalRoster, 0)]
[h: UnactiveRoster = json.get(TotalRoster, 1)]

<!--========================================================================================================-->
[FOREACH(Character, ActiveRoster, "<br>") , CODE:
{
[h: count=roll.count]
[h: CharSlot = json.get(ActiveRoster, count)]
[h: CharName = json.get(CharSlot, "Character")]
[h: CharacterList = listAppend(CharacterList, CharName)]
} ]

[h: Pause("CharacterList")]

<!--========================================================================================================-->
the code snippet that is doing it is between step 1 comment line and the next comment line of the bar of equal signs.
I can't say I follow everything you've said but if you run the macro on the Lib token, when you do this:

Code: Select all

[h: CharacterList = listAppend(CharacterList, CharName)]
You're overwriting that Property on the token. And you're doing it for each Character in the Active Roster.

Don't use the name of a Property as a variable unless you're trying to overwrite it.

I always suggest that people use lower case variable names when they're writing to a variable that they believe is local to only the macro and capitalized variable names when they know (and are intentionally) trying to modify a Property on a token. MT isn't case sensitive with variables, but it shows intent.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

Merudo
Giant
Posts: 228
Joined: Wed Jun 05, 2019 7:06 am

Re: Macro somehow editing lib token properties without being told to.

Post by Merudo »

Personally I add a "v" in front of the name of a local variable, this way I never overwrite a property by mistake.

JawareBloodriver
Kobold
Posts: 11
Joined: Wed Oct 03, 2018 10:19 pm

Re: Macro somehow editing lib token properties without being told to.

Post by JawareBloodriver »

wait a minute.... hold up....

i was under the impression that you had to use setLibProperty() in order to modify a library tokens properties.

are you guys saying that I dont have to use that to do it?

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Macro somehow editing lib token properties without being told to.

Post by aliasmask »

properties that show up in the token type are global variables and can be reference anywhere on that token. It's just better to use setProperty especially now in the way networking is done.

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Macro somehow editing lib token properties without being told to.

Post by Full Bleed »

JawareBloodriver wrote:
Sun Oct 06, 2019 11:48 pm
wait a minute.... hold up....

i was under the impression that you had to use setLibProperty() in order to modify a library tokens properties.

are you guys saying that I dont have to use that to do it?
If being called from another token or lib token then, yes, you have to use get/setLibProperty.

But not if the the macro is being run on the lib token. In that case, you can read local token properties with local variables of the same name.

On your lib token create a macro with this:

Code: Select all

[r: CharacterList]
and this

Code: Select all

[r: CharacterList = "poof"]
Now, if you put a macro on another token or another lib token you will need to use get/setLibProperty to pull or change the CharacterList property (from that separate lib token.)

So, bottom line, don't use local variable names that are the same as local property names. And if that's hard for you to track don't *ever* use variable names that are the same as property names and only pull and set property values using get/setLibProperty and get/setProperty.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

Phergus
Deity
Posts: 7132
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: Macro somehow editing lib token properties without being told to.

Post by Phergus »

Full Bleed wrote:
Mon Oct 07, 2019 9:26 am
So, bottom line, don't use local variable names that are the same as local property names. And if that's hard for you to track don't *ever* use variable names that are the same as property names and only pull and set property values using get/setLibProperty and get/setProperty.
That will save you much grief when creating macros and trying to debug them.

JawareBloodriver
Kobold
Posts: 11
Joined: Wed Oct 03, 2018 10:19 pm

Re: Macro somehow editing lib token properties without being told to.

Post by JawareBloodriver »

Ooooooooohhhhhhhhhhhhhhhhh........

that explains a lot actually.........

.....

Thanks my fellow companions. That does help a lot.

I had no idea it worked that way. I just thought that token properties was a way to save information for use outside of the individual macros and game sessions.

I guess that does explain why when i made macros doing stuff from called global macros it didnt do it. but if i would run the macro on the token it would very much break.

Post Reply

Return to “MapTool”