Advertisement Create a free account

[Sheet Worker] Can you use "on clicked:" for a button in a repeating area?

1547230588
And if so, how?  This doesn't work: <fieldset class="repeater">     ...     <input type=button name=act_my-button>     ... </fieldset> on ("clicked:repeater:my-button", function(eventInfo) {     ... }) The event handler never gets triggered.  If it matters, the button is also triggering a rolltemplate.- and that works. What I need to do is change some attributes (all within the context of the single repeating row) as a consequence of the button being hit.  Specifically, the button generates a ranged weapon attack roll, and I'm trying to decrease the loaded ammunition in the weapon when it is fired. All suggestions welcome!
1547241191

Edited 1547241248
Scott C.
Pro
Sheet Author
API Scripter
In a specific situation, it is possible to use the on:clicked  event listener. First though, there's a misconception in your code above. Buttons are not input elements, they are their own html element: <input type=button name=act_my-button> should be <button type='action' name='act_my-button'>Button Text</button> or <button type='roll' name='roll_my-button' value='what you want sent to chat'>Button Text</button> Both of these buttons are valid on character sheets, but have different effects. The action button can be clicked for an effect to take place (and you would use on:clicked  to listen for that click). The roll button sends a macro to chat and clicking it does not create an event for on:clicked  to listen for. So, if you're using an action button, then yes you can listen for the click. Additionally, I might recommend some changes to your proto sheetworker: on ("clicked:repeater:my-button", function(eventInfo) {     ... }) This is technically correct, but unless you are planning on having buttons with the same name in multiple repeating sections, you could simply change this to: on ("clicked:my-button", function(eventInfo) {     ... }) Hope that all helps, Scott
1547244423
The <input type="button"> vs <button...> was just carelessness.  (I was stripping down my code to siimplify the example and got a bit carried away.) So, the short answer is... I can have a button that EITHER triggers a sheet worker OR triggers a roll template.   I sorta expected that.  So the next question becomes... can I have the sheetworker trigger the roll? (Oh, and thx for the simplifer on the "clicked:"  Does that apply to on("changed:repeating-attrib... as well?)
1547251513

Edited 1547251659
Scott C.
Pro
Sheet Author
API Scripter
Bob O. said: So, the short answer is... I can have a button that EITHER triggers a sheet worker OR triggers a roll template.   I sorta expected that.  So the next question becomes... can I have the sheetworker trigger the roll? Short answer is no. The slightly longer answer is that you might be able to accomplish this whenever charactermancer functions go live for the community sheet authors  Edit:as for the change event,see the wiki for full details: https://wiki.roll20.net/Sheet_Worker_Scripts#change:.3Cattribute_name.3E
1547760764
Scott C. said: ... Additionally, I might recommend some changes to your proto sheetworker: on ("clicked:repeater:my-button", function(eventInfo) {     ... }) This is technically correct, but unless you are planning on having buttons with the same name in multiple repeating sections, you could simply change this to: on ("clicked:my-button", function(eventInfo) {     ... }) Hope that all helps, Scott FYI... using the "clicked:repeater:my-button" didn't seem to work at all, but clicked:my-button does! So... I can create an "action" button in my repeating area... and I can get into an event listener when it gets clicked. But... The sheet worker doesn't seem to know what row it was called from... attempts to use the  "repeater_attribute-name" syntax that works for on:change events that are limited to attributes within the row doesn't work (I get an error indicating that there's no current row id).   And since the "clicked" event doesn't pass an eventInfo object, I use the can't use the "pluck the row ID out of eventInfo.sourceAttribute". So... any ideas on how I can tell the script what row I'm working on?
1547761844

Edited 1547762556
Scott C.
Pro
Sheet Author
API Scripter
Hmm, that's interesting. There's no event info at all? Hmm. I'd say it's a bug/not fully implemented feature. I'll have to dig in and do some testing myself. EDIT: Hmm, interesting, so there is an event created, and it does have the expected keys, but all of them except for triggerName are undefined.
1547770599
I used the "fake button made from transparent checkbox over a span that looks like a button" approach to get around this for now, but maybe someday they'll provide a proper way to do this.