Working On Another Token

Developer discussion regarding MapTool 1.4

Moderators: dorpond, trevor, Azhrei

Forum rules
Posting now open to all registered forum users.
Post Reply
Lord_Ashes
Kobold
Posts: 15
Joined: Tue Jun 18, 2019 7:43 pm

Working On Another Token

Post by Lord_Ashes »

I am trying to create a fairly simple macro but I am running into problems acting on a selected token.

I have a token (currently not a lib token) which has a bunch of GM related macros. One of these macros creates an input which provides a drop down list of all PCs and NPCs and provides a text box for a numeric values. The intention of the macro is to adjust the selected token's life by the indicated amount and update their health bar.

I created a version of this macro on individual tokens (obviously without the target selection drop down) and I was able to perform the life adjustment, storage of the new value and update of the health bar without any probelms.

However, when I try to do the same from the GM token, the selection process seems to work but no matter what I try I can't seem to get the getProperty and setProperty to work correctly on the selected token.

I tried switchToken(), I tried using the token() roll modifier, I tried specifying the id in getProperty() and setPropety(). In most cases, the value returned by getProperty() is an odd value which does not match the selected token's visible property value.

(The GM macro does have the "Allow Player Edit" unchecked so as to be a Trusted Macro)

Here is my macro content. I have added comment lines prefixed by ";" just for more explanation here (they are not included in the actual macro):

Code: Select all

; Initialize lists for PCs, NPCs and a combined list. This is so that all PCs appear in alphabetical order before all NPCs in alphabetical order.
[h: tokenImages = ""]
[h: tokenImagesPC = ""]
[h: tokenImagesNPC = ""]
; Get a list of all PCs
[h: tokens = getTokens(',','{ pc: 1 }') ]
[foreach(tkn, tokens, ""), CODE:
{
    ; Add the name and image asset to the token list
    [h, token(tkn): tokenImagesPC = tokenImagesPC + getName(tkn) +" " + getTokenImage() +"," ]
}]
; Sort the PCs list alphabetically
[h: tokenImagesPC = listSort(tokenImagesPC,"A") ]
; Remove the first empty entry generated by the trailing comma in the list
[h: tokenImagesPC = listDelete(tokenImagesPC,0) ]

; Get a list of all Foes (using a custom State). This avoids getting all NPCs of which many may not be foes.
[h: tokens = getTokens(',','{ setStates:["Foe"] }') ]
[foreach(tkn, tokens, ""), CODE:
{
    ; Add the name and image asset to the token list
    [h, token(tkn): tokenImagesNPC = tokenImagesNPC + getName(tkn) +" " + getTokenImage() +"," ]
}]
; Sort the NPCs list alphabetically
[h: tokenImagesNPC = listSort(tokenImagesNPC,"A") ]
; Remove the first empty entry generated by the trailing comma in the list
[h: tokenImagesNPC = listDelete(tokenImagesNPC,0) ]
; Combine PC and NPC lists together
[h: tokenImages = tokenImagesPC + "," + tokenImagesNPC ]
; Generate input
[h: status=input("target|"+ tokenImages +"|Select Target|LIST|SELECT=0 ICON=TRUE ICONSIZE=30",
                           "transfer|1|HP Adjustment|TEXT|WIDTH=12")]
; Get the selected entry from the list
[h: selection = listGet(tokenImages, target) ]<BR>
; Extract the token name by removing the asset portion of the selection
[h: selection = substring(selection, 0, indexOf(selection, "asset:")-1) ]

; Switch to the selected token
[h: switchToken(selection)]

; Verify that switch worked by checking the current token
Token: [r: getName(currentToken())]<BR>

; Read the MaxHP token property
MaxHP:[r: life = getProperty("MaxHP") ]<BR>
 
Obviously the above code does not actually adjust the HP and Health Bar. It just tries to read the MaxHP for the selected character.

The results of the macro indicate that the current token is the selected token but the value read back does not match the selected character's MaxHP value. For example, when I used this on a token whose MaxHP is set to 15, the macro returned a value of 0.

It almost looks like that the visible token property is not being recognized and it is generating a "hidden" property instead (starting with a default value of 0).

Is this somehow a problem because the GM token that is executing the macro needs to be a lib token?

Post Reply

Return to “MapTool 1.4”