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

Mod to create/set repeating attr does not trigger sheetworker.

1704244404

Edited 1704244606
vÍnce
Pro
Sheet Author
Not sure if this should be posted in Mods (API Scripts) or Character Sheets & Compendium ... I'm having an issue getting a mod command (tried scriptcards and chatsetattr) that creates a repeating attribute to trigger the sheetworker to do more stuff™ Everything works when interacting on the sheet.  events and calcs work as expected.  I can get the mod command to create and set the repeating attr, but the sheetworker that is supposed to fire when those fields change does not register to the sheetworker.  Log shows nothing on eventInfo.sourceType.  Didn't this used to show "API" like "Player" and "Sheetworker"? here's a cut down version of my test case; <label> Caster Class 1:<input type="text" name="attr_caster_class1_name" value="" /> Level:<input type="text" name="attr_caster_class1_level" value="0" /> </label> <label> Caster Class 2:<input type="text" name="attr_caster_class2_name" value="" /> Level:<input type="text" name="attr_caster_class2_level" value="0" /> </label> <fieldset class="repeating_spells"> <div style="border: 1px solid; padding:5px;"> Name: <input type="text" name="attr_spell_name" /> Class: <select name="attr_spell_caster_class"> <option value="0">n/a</option> <option value="1" selected>Caster 1</option> <option value="2">Caster 2</option> </select> <input type="text" name="attr_spell_caster_class_name" value="" readonly /> Lvl: <input type="text" name="attr_spell_caster_class_level" value="0" readonly /> </div> </fieldset> <script type="text/worker"> on('change:repeating_spells:spell_name change:repeating_spells:spell_caster_class', (eventInfo) => { console.log(`sourceType:${eventInfo.sourceType}`); const id = eventInfo.sourceAttribute.split('_')[2]; getAttrs(['repeating_spells_spell_caster_class', 'caster_class1_name', 'caster_class1_level', 'caster_class2_name', 'caster_class2_level'], (v) => { const output = {}; const thisClass = +v.repeating_spells_spell_caster_class || 0; console.log(`thisClass: ${thisClass} id: ${id}`); if (thisClass === 0) { output.repeating_spells_spell_caster_class_name = ''; } else if (thisClass === 1) { output.repeating_spells_spell_caster_class_name = v.caster_class1_name; output.repeating_spells_spell_caster_class_level = +v.caster_class1_level || 0; } else if (thisClass === 2) { output.repeating_spells_spell_caster_class_name = v.caster_class2_name; output.repeating_spells_spell_caster_class_level = +v.caster_class2_level || 0; } setAttrs(output, {silent: true}); }); }); </script> chatsetattr mod to try; !setattr --sel --replace {{ --repeating_spells_-CREATE_spell_name|Test --repeating_spells_-CREATE_spell_caster_class|2 }} scriptcard mod to try; !script {{ --!or:@{selected|character_id}:spells| spell_name:Test| spell_caster_class:2| }} image example; I entered some values to work with in the non-rep fields.  Created a new repeating_spells and the sheetworker updates all fields as expected as soon as I enter the spell_name. Awesome. BUT the next repeating_row was created with a mod.  It sets the spell_name and the spell_caster_class correctly, but the other fields never get updated. Not awesome. Any help/suggestions?  Thanks
1704249827

Edited 1704249929
GiGs
Pro
Sheet Author
API Scripter
There used to be a problem with chatsetattr.  Sheetworker events are not automatically triggered by scripts. You need to use a special script command to create events that sheet workers will respond to (setWithWorker), and for a time chatSetAttr didn't use that. Is it possible you are using an old version of chatSetAttr? Have you tried doing this in a separate campign - same sheet, new install of chatSetAttr to see if it's just an issue with that campaign. Also, have you tried with a different character sheet? Ideally in a different campaign. Does the issue happen with both chatsetAttrs and scriptCards? Do normal attributes (not repeating ones) work okay? Does the sheet worker work correctly if you use getSectionIDs, rather than the id-less format? (The more I think about it, the more I think this is the issue.)
1704257886
vÍnce
Pro
Sheet Author
Thanks for the reply GiGs. Is it possible you are using an old version of chatSetAttr? Using the latest one-click versions of chatSetAttr and SscriptCards. Have you tried doing this in a separate campign - same sheet, new install of chatSetAttr to see if it's just an issue with that campaign. This is a test campaign in sandbox.  Nothing else there except for this scrap of code. Also, have you tried with a different character sheet? Ideally in a different campaign. I think this may have "solved" this.  I made a new character and the scripts now seem to work with the new character.  WTH? My test character had no other attributes other than what was included in this bit of sample code. I even checked the A&A tab and removed some older unrelated attributes from previous testing. Maybe there was some hidden residual attrs from past tests that were interfering?  IDK.  Seems unlikely if they were completely different attr names. Does the issue happen with both chatsetAttrs and scriptCards? Happens with both scripts. Do normal attributes (not repeating ones) work okay? Haven't tried this yet. Does the sheet worker work correctly if you use getSectionIDs, rather than the id-less format? (The more I think about it, the more I think this is the issue.) I originally had it setup with getSectionIDs and thought it might be the issue, so considering it was only working from within the actual repeating_spells trigger I tried to simplify it. ;-) So it looks like I had to use a whole new character.  That really doesn't seem very comforting as a solution though.  Sadly I already deleted the old test character before I thought of duplicating it or moving it to the vault and back to see if that could solve it instead of abandoning the sheet.  I do have the initial character and campaign where I was noticing the behavior originally which coerced me into making this case-study in isolation.  I'll see if I can find another option besides deleting the character though. Thanks again GiGs.
1704261031

Edited 1704261156
GiGs
Pro
Sheet Author
API Scripter
vÍnce said: Also, have you tried with a different character sheet? Ideally in a different campaign. I think this may have "solved" this.&nbsp; I made a new character and the scripts now seem to work with the new character.&nbsp; WTH? My test character had no other attributes other than what was included in this bit of sample code. I even checked the A&amp;A tab and removed some older unrelated attributes from previous testing. Maybe there was some hidden residual attrs from past tests that were interfering?&nbsp; IDK.&nbsp; Seems unlikely if they were completely different attr names. If you are in the sandbox, and changing the character fixed it, the problem you had was some sort of sheet corruption. I have seen this happen a lot . If I'd known you were in the sandbox, this is the first thing I'd have suggested because it's so common for me. Have you been editing the HTML/CSS/JS for the sheet? I find if I am editing the code for the character sheet a lot, sheet corruption is inevitable (bear in mind I do a LOT of sheet editing, so it might not be as inevitable for others). Whenever something stops working the way it should, I always create a new character to see if the problem goes away. As it happens, I wrote about this back at the start of December: <a href="https://cybersphere.me/sheet-corruption/" rel="nofollow">https://cybersphere.me/sheet-corruption/</a> You mention it's not very comforting having to change the character. That shouldn't worry you. I think this is an issue specifically with the custom sheet sandbox, and it wont happen in normal campaigns.
1704262385

Edited 1704262736
vÍnce
Pro
Sheet Author
I recall reading that comment on your site.&nbsp; ;-) This was a separate sandbox and I just culled out the code from my bigger dev sandbox that has all the sheet code.&nbsp; I'm still experiencing this issue using the bigger dev sandbox though and just recreating a new character is not really going to be acceptable for obvious reasons. As a temp workaround I've found I can add a hidden input that matches the select and remove "selected" from my default option. After doing this, the sheetworker seems to trigger properly after the API command sets the attr. example (like my OP above but this is from the actual sheet code); &lt;span class="span-all inline-label"&gt; &lt;label&gt; &lt;select class="select width-medium" name="attr_spell_caster_class" title="@{repeating_spells_$X_spell_caster_class}"&gt; &lt;option value="0"&gt;n/a&lt;/option&gt; &lt;option value="1" selected&gt;Caster 1&lt;/option&gt; &lt;option class="toggle-caster2" value="2"&gt;Caster 2&lt;/option&gt; &lt;/select&gt; &lt;input type="hidden" name="attr_spell_caster_class" value="1" /&gt; &lt;input type="text" class="auto-width shrink-on-placeholder" name="attr_spell_caster_class_name" value="" title="@{repeating_spells_$X_spell_caster_class_name}" placeholder="add caster class" readonly /&gt; &lt;/label&gt; &lt;label class="right" style="min-width: 3em; max-width: 4em; margin-left: 5px;"&gt; &lt;span&gt;Lvl&lt;/span&gt; &lt;input type="text" class="width-smallest" name="attr_spell_caster_class_level" value="0" title="@{repeating_spells_$X_spell_caster_class_level}" readonly /&gt; &lt;/label&gt; &lt;/span&gt; another workaround seems to be; edit the mod script to include "empty" attrs for those fields the sheetworker is auto-filling when triggered. example; !setattr --sel --replace {{ --repeating_spells_-CREATE_spell_name|Test --repeating_spells_-CREATE_spell_caster_class|2 --repeating_spells_-CREATE_spell_caster_class_name| --repeating_spells_-CREATE_spell_caster_class_level| }} I'll try moving to a Custom game and see if this is possibly a "sandbox-only" issue.
1704264423

Edited 1704264517
vÍnce
Pro
Sheet Author
and... it appears that the mod works as expected in a Custom game without the extra workarounds mentioned above. (ie the hidden input and/or the extra empty attrs in the mod script)&nbsp; I imported a character from my dev sandbox that was not triggering the worker properly in the sandbox and the same character now seems to trigger fine when using the same scriptcard or chatsetattr commands and sheet code in the custom game. So where does that leave us?&nbsp; Seems like the dev sandbox "can" be a little unreliable.
1704305247

Edited 1704305301
GiGs
Pro
Sheet Author
API Scripter
You're using a dev sandbox? I thought they shut down dev? If it still exists on your end, I recommend transitioning away from it. It;s not going to get maintenance updatesm, it's just going to die.
1704309655
vÍnce
Pro
Sheet Author
My bad GiGs.&nbsp; Not the actual Dev server.&nbsp; Just referring to it as my "development" sandbox, meaning it was where the full sheet code was being developed and not a "side" sandbox that was testing issues or theories in isolation.
1704310879
GiGs
Pro
Sheet Author
API Scripter
I see :) You said you were still having the issue with one of your sandboxes. Does this happen if you create a new sandbox, and load the character sheet in that one? Also is it only happening with dertain characeters? Can you avoid it by creating new characters?
1704316910

Edited 1704320007
vÍnce
Pro
Sheet Author
GiGs said: I see :) You said you were still having the issue with one of your sandboxes. Does this happen if you create a new sandbox, and load the character sheet in that one? Also is it only happening with dertain characeters? Can you avoid it by creating new characters? API Result - no html tricks API Result - with hidden input and "selected" removed Sandbox - Old Character Fails Works Sandbox - New Character Fails Works Custom Game - Old Character Works Works Custom Game - New Character Works Works Custom Game - Newest Character Works Works I used transmogrifier to copy over "Old Character" from my main working sandbox. "New Character" was created in the sandbox game. I used transmogrifier to copy over Old and New to the Custom game. The "Custom Game Newest Character" was only created in the custom game. The only thing I changed in the code was either using the select with "selected" (no html tricks) or removing "selected" and adding a hidden input matching the select (using html tricks). Seems hit or miss (mostly miss in sandbox) without the extra html.