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

Action Buttons in the Macro Bar, a simpler trick(?!)

1713021389
Marco M.
KS Backer
Sheet Author
API Scripter
Compendium Curator
Since the thread is closed, I cannot comment or ask a question there.  Here is the  original post . The author suggests using the character name to do it, but it is probably simpler to use character_id that is immutable. Thus, the final function would become < ! - - The visible and draggable button for the macro bar - - > < button type = "roll" name = "roll_athletics" value = "@{athletics_action}" > Athletics < /button > < ! - - The invisible button allowing the use of custom roll parsing - - > < button type = "action" name = "act_athletics-action" class = "hidden" > < /button > < ! - - The invisible field for the attribute which contains the ability call - - > < input type = "hidden" name = "attr_athletics_action" value = "" > [...] < script type = "text/worker" > on ( "sheet:opened" , function (eventInfo) { getAttrs ([ "character_id" , "athletics_action" ], function (v) { var attrsToChange = {}; attrsToChange[ "athletics_action" ] = "%{" + v[ "character_id" ] + "|athletics-action}" ; setAttrs (attrsToChange); }); }); < /script > It's a small change, but I think it might avoid triggering every time the name is changed for any reason, and it might avoid bugs due to the sheet author forgetting the second trigger. (I tested it on my side on a test sheet, if there is something I am missing please let me know)
1713024703

Edited 1713037908
GiGs
Pro
Sheet Author
API Scripter
I think the reason the original method didn't use character_id is because people weren't aware there was a character_id attribute you could reference like this. It's a nice idea but it makes me wary because It might not always be accessible the way it is at the moment. character_name is also more readable - the  text of those action buttons will be seen by some people. Being triggered on character_name changes is not much of a problem - it's going to happen so infrequently. If it is reliable though, you can avoid much of the code Scott posted in the previous thread - that code is great but it's a shame we need it.