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

[Help] Listening on change in repeating fields with sendChat

Hi, i have a little problem right here: I have sheetworker that listening on a checkbox (on/off state) and do some calculations with the rest of the values in this repeating field, but the sheetworker is client sided so i can't use the sendChat()-function what i need. So the calculations will be fine and don't need to move to the API, what i need is just: if somebody hit the checkbox in the repeating field, make sendChat('foobar'); with some values of the character.  So, does somebody have a workaround or a better idea for that?
1543406322

Edited 1543406431
GiGs
Pro
Sheet Author
API Scripter
You cant sendChat from a sheet worker. the only way to send anything to chat from a character sheet is by manually pressing a button. The only way is to use an API script which monitors the checkbox, and then reads the attributes and sends the stuff to chat.
1543406626
GiGs
Pro
Sheet Author
API Scripter
I guess you could do it with a sheet worker, if you dont mind using a checkbox, a placeholder attribute, and a roll button. You could have a sheetworker triggered when you check the checkbox. That sheetworker does the calculation, and populates a 'printout' attribute with formatted text. Then the roll button has value="@{printout}", so when you click it, the sheet workers printout gets printed to chat.
1543414614

Edited 1543414797
Hi, i fully understand that the sheet worker doesn't have the ability to use sendChat(), thats why i need the workaround. So basically you have manually to push the button to "wearing" it AND hit the checkbox or it is possible to change the on/off value (also checked attribute!) on the checkbox via sheet worker? And how it works with the API to monitor a repeating checkbox? The API documentation doesn't show that. I tried around with the on('change:repeating_checkbox')- function. 
1543417596

Edited 1543417626
GiGs
Pro
Sheet Author
API Scripter
It's possible to change the on/off checkbox value with a sheetworker, but that won't actually trigger a button. They are separate. So the ideal way just using the character sheet would be: have an on/off checkbox. When clicked on, this triggers a sheet worker. The sheetworker builds whatever you want to print out, and puts it in an attribute. It also unchecks the checkbox so its reset to off. Then the roll button can be clicked to send the result to chat. To use the API, you'd have a script built like this (no actual code, just the steps needed): on('change:attribute', function(obj, prev) { // check obj is the checkbox attribute, and that it is now checked // If so, get the character id this attribute change occurred on // get the values of any attributes you need // build your chat string // send to chat }); Without knowing exactly what it is you want to print to chat, it seems like the sheetworker method might actually be simplest, if a bit clunky and less automatic.