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 .
×
Create a free account

Modify attribute with ChatSetAttr then trigger action button

I have a field and a button. The button uses the value of the field to perform some calculations. I'd like to use ChatSetAttr to update the value of the field, then trigger the action button. However when I try this, the !setattr command never seems to be triggered. Code: <input type="number" placeholder="Damage" name="attr_armordamage" /> <button type="action" name="act_armorapplydamage">Apply Damage</button> What I've tried: Setting the value of the `armordamage` field works great: !setattr --nocreate --name Sam Smith --armordamage|15 Triggering the action button works great: %{Sam Smith|armorapplydamage} If I combine them like this, the button gets triggered but the field never gets updated: !setattr --nocreate --name Sam Smith --armordamage|15 %{Sam Smith|armorapplydamage} If I try to inline the `!setattr` call, the same thing happens. The button gets triggered but the field never gets updated: &{template:custom} !setattr --name Sam Smith --armordamage|15 !!! {{Sam Smith=%{Sam Smith|armorapplydamage}}} How do I combine them into a single macro?
1640760225
GiGs
Pro
Sheet Author
API Scripter
When you run a macro, the first thing roll20 does is grab the value of all attributes referenced in the macro. So the macro will always use the value of the attribute as it was before the macro started. Have you checked the attribute after the macro finishes, to see if the attribute has been updated?
I've confirmed that the attribute never updates, even after the macro finishes. So the macro will always use the value of the attribute as it was before the macro started. Is there a way using parentheses or something to get the attribute update to occur before triggering the Action button?
1640786316
David M.
Pro
API Scripter
I've experienced some cases where multiple commands get processed in a different order or sometimes are skipped (though that is usually when stacking multiple !api commands in a macro). Not sure if that is what is happening for you. Even if the setattr syntax works on its own, you might run into some asynchronous timing issues by combining both commands into a single macro. !setattr takes some time to process, and it might not be completed by the time the ability is triggered. In that case, it's probably best to keep them in separate macros. I suppose you could also write a Scriptcard to call setattr and then print a button in chat to call the ability. Still two clicks, though.
1640788028

Edited 1640788069
Grinning Gecko
Pro
Sheet Author
I suppose you could also write a Scriptcard to call setattr and then print a button in chat to call the ability. Still two clicks, though. Ya, I'm doing that with Chat Menus right now. I run a macro which prompts for damage, then creates the following menu. It works, but it's not as automated as I'd like.