Problem with a macro in Selected Window

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
Posts: 3
Joined: Sat Feb 20, 2021 7:37 pm

Problem with a macro in Selected Window

Post by reganark »

Hello! I have a problem with a macro, its an attack macro that uses properties from a selected token, it calls a function in a library token I have set up to make all the rolls and calculate damage. My problem is that it works perfectly if I use it from the Global or campaign windows, but when I try to use it from the selected window it shows an error. I know I could make my players use the macro from other window, or just use it myself, but both my players and myself are new to maptools and I would like for them to have it easy so that they cant use the macros in other tokens, and I know rolling your attack is part of the thrill of playing. When I use it from the selected window it gives me an error saying that I have no permission to access another token in the function "getProperty". Here is the code for the macro, but I'm not sure if it is a coding problem:

[h: weapon = EquippedWeapon]
[h: attacker = getName()]
[h: target = selectToken()]

[h: originalLP = getProperty("LPCurrent", target)]
[h: criticalThreshold = originalLP / 2]

[r: attackFunction(weapon, target, attacker, 0)]

[h: DamageTaken = originalLP - getProperty("LPCurrent", target)]
[r: if(DamageTaken > criticalThreshold,
add("<p style='background-color: red;'>Critical!!! ", "</p>"),
"" )]

[h: setState("Acted", 1)]

I don't think there is a problem with the function from the library token, but it doesnt even get to that part when I use it from the selected window so I'm not completely sure.
I'm sorry if this isnt supposed to be posted here, please let me know if I should change it.
Hope you al have a nice day!!

Post Reply

Return to “Macros”