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

Trigger custom roll parsing from macro

1635600693

Edited 1635600960
.Hell
Sheet Author
Hi everyone, is it possible to trigger the custom roll parsing from a macro? The use case is to have a chat menu which triggers rolls that should be exactly as if they were pushed on the sheet
1635606098
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Yes, I've got several in progress sheets where this happens. The thing to remember is that only the button name is sent in the event object when an action button is triggered from chat, so you have to set up your sheetworkers so that they only require the button name to figure out what needs doing. Otherwise, it works the exact same as if someone clicks on the actual button on the sheet.
1635608121
.Hell
Sheet Author
Sorry it is not clear to me what you mean. Can you post an example?
1635611054
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Sure, so, if we have the below button < button class = "roller" name = "act_intellect" role = "header" aria-level = "5" data-i18n = "intellect" type = "action" title = "%{intellect}" > And the below, very basic, sheetworker to react to clicking on that button: on ( 'clicked:intellect' ,( event ) => {   console. table ( event ); }); We get two very different events logged depending on how we call the button. Clicking on the sheet itself gives us all the htmlAttributes: While calling the button from chat like you would with a chat button gives us an empty htmlAttributes object: So, the only information that is reliably available from the button click event is the triggerName property of the event. This means that your sheetworker to initiate the roll needs to know what to do based only on the name of the button without needing to rely on any information stored in the other html attributes.
1635616790
.Hell
Sheet Author
I think there is a little misunderstanding. The button is in a repeatable row and does not have a unique name. So I copied what is send to chat via up arrow. But this circumvents the custom roll parsing where I calculate some data to show additional roll-template elements
1635619396
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
It's still perfectly doable with repeating sections, my example just didn't include it. If we add clicked:repeating_skill:roll  to our listener, we can observe the event that is passed from that. Just like the non repeating section button, it has htmlAttributes when clicked on the sheet, and they are missing from the chat call triggered event. Click on sheet: Triggered from chat: Note that the repeating button clicks have a sourceAttribute value, but I tend to ignore this so I can write generic roll handling functions. Also, something I wasn't aware of until I made this demo, the triggerName uses the same reference syntax as was used in the chat command, so if the user called it with a relative reference (e.g. $0,$1, etc), that's what is used as the triggerName. If they used a specific rowID in the call, that is used. So, you'll need to find the order of the ids and be able to reference them to get the actual row ID for further use. I've got a function that returns the ordered IDs, I'll see if I can dig that up.
1635780642
.Hell
Sheet Author
I tried around a bit, but didnt get it to work. It is still unclear for me how I get from the call of the template in the macro to the usage of custom roll parsing
1635808840

Edited 1635808950
Oosh
Sheet Author
API Scripter
I don't think you can trigger any roll parsing by sending anything to chat - I believe the sandbox is limited to events on the character sheet. You'd need that API to listen for 'chat:message' events. What will trigger an event handler is directly calling the button with %{repeating_shoes_$0_equipshoes} , or %{repeating_shoes_-rowid_equipshoes} . As Scott has pointed out above, using the $0 indexing (which you need to for a universal macro, unless you want to do some custom menu construction on every repSec change) you'll need to find the rowid before roll parsing will work. There's a function on the wiki that does this - it's just a getSectionIDs combined with that section's _reporder to account for the user rearranging the rows. Sounds like Scott might have a Scottified version, which he's about to share.... :)