Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
May your rolls be merry + bright! 🎄
Create a free account

Macro processing order

1585257135

Edited 1585259956
I have done a fair bit of reading and I just can't get this to work right. I have this macro !setattr --sel  --modb  --HP|?{Amount|0} !token-mod --set bar3_value|[[round((@{selected|HP}/@{selected|HP|max})/.25)]]|4 /me red bar set to @{selected|bar3} of @{selected|bar3|max} The  HP is linked to bar1 (not that I think it matters but just for context) which is only visiible to the controlling player and GM bar3 is the red bar ( unlinked ) that I round to the nearest 25%, that is what everyone can see, approximately how hurt someone is. It works but the red bar is getting updated one run after the HP is changed. So I start at 100HP our of 100 I run the macro and apply -50HP, putting the green bar at half but the red bar is unchanged I can run it again and add 50HP back making HP100 and the green bar goes to full and the red bar goes to 1/2 So each time I run the macro the red bar is one execution behind, so I think it has to do with the order things are parsed and executed. It's worth pointing out when I do this, the text output ( /me red bar set to @{selected|bar3} of @{selected|bar3|max} ) shows the correct value but the bar itself does not. I have tried numerous combinations of { and [[ and putting the red bar in it's own MACRO and calling that but the problem persists I bet it's something super simple someone will point out...
1585265511
GiGs
Pro
Sheet Author
API Scripter
This is the roll20 processing order. When you launch a macro, it gets all attribute references mentioned in the macro, then does any queries. So in your macro, it gets the HP value before your query changes it. What you can do is reuse a query value to avoid this !setattr --sel  --modb  --HP|?{Amount|0} !token-mod --set bar3_value|[[round((?{Amount}/@{selected|HP|max})/.25)]]|4 /me red bar set to [[round((?{Amount}/@{selected|HP|max})/.25)]] of @{selected|bar3|max} I havent used token-mod in a while, is that token-mod command correct? The |4 at the end confuses me. Also why are you dividing by 0.25?
1585266286

Edited 1585271506
That's the max value, so !token-mod --set bar3_value|3|4 should set it to 3 out of 4 Say I have 100HP and take 25 damage, I should end up at 3/4 red bar (it always works if I run it by itself, so the token-mod syntax should be good) Amount is the damage taken or healed, but I get your intent, which is to reuse {amount}. Ignoring the fancy math in the /me, if I just do /me HP modified by ?{Amount}, red bar set to @{selected|bar3} of @{selected|bar3|max} the text output is correct xxxx HP modified by -50, red bar set to 2 of 4 But the red bar is still showing at full Side note, the token-mod format was wrong, you were correct, I was using the setattr syntax I changed it but it doesnt help the order these resolve in !token-mod --set bar3_value|[[round((@{selected|HP}/@{selected|HP|max})/.25)]] bar3_max|4 I think since I had a value of 4 in there anyway it wasn't doing anything with that |4 but it wasn't really hindering the macro either The reason to divide by .25 is I only show the bar3 health bar to the nearest quarter for all players to see. In our game we figure in combat you can likely tell when someone is getting worn down and battered and that a person at 1HP doesn't look or act as spry as a person at full health, so we let them see at a glance approximately how healthy someone is. This may not apply to elementals or construct, incorporeal....
I got it working you set me on the right track I ended up with this !setattr --sel  --modb  --HP|?{Amount|0} !token-mod --set bar3_value|[[round(( ( @{selected|HP} +?{Amount}) /@{selected|HP|max})/.25)]] bar3_max|4 /me HP modified by ?{Amount}  red bar set to @{selected|bar3} of @{selected|bar3|max} So I needed to repeat the math for the token-mod that was done for the HP attribute, thanks for getting the gears turning!
1585281472
GiGs
Pro
Sheet Author
API Scripter
Congrats!