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

Checkboxes and Repeating Sections and Sheetworkers not interacting

1726839325
Steve
Pro
Sheet Author
It is more than likely that I am trying to do too much again - but I feel like I am close. I just can't get the first sheetworker to trigger the second one without causing other issues (eg, if I take out the return statement, the spell equips, but the checkboxes are all blank and there's other unwanted behaviours caused by the sheetworker affecting itself).  With the current code below, when either of the spells are activated they successfully populate a row on the repeating section, they even check the 'equipped' box - but it doesn't actually equip it, and it doesn't uncheck the current weapon either.  on('change:steel_claw change:vorpal_blade', function() {     getAttrs(['steel_claw', 'vorpal_blade'], function(values) {         const steelClawActive = values.steel_claw === "1";         const vorpalBladeActive = values.vorpal_blade === "1";         if (steelClawActive || vorpalBladeActive) {             getSectionIDs('repeating_meleeweapons', function(ids) {                 const attrsToGet = ids.map(id => `repeating_meleeweapons_${id}_meleeweaponname`);                                  getAttrs(attrsToGet, function(weaponValues) {                     const steelClawExists = ids.some(id => weaponValues[`repeating_meleeweapons_${id}_meleeweaponname`] === 'Steel Claw');                     const vorpalBladeExists = ids.some(id => weaponValues[`repeating_meleeweapons_${id}_meleeweaponname`] === 'Vorpal Blade');                     let update = {};                     let newRowId; // Define here to access later                     if (steelClawActive && !steelClawExists) {                         newRowId = generateRowID();                          update[`repeating_meleeweapons_${newRowId}_meleeweaponname`] = "Steel Claw";                         update[`repeating_meleeweapons_${newRowId}_meleeweapon`] = "Magic Talon";                         update[`repeating_meleeweapons_${newRowId}_meleeabr`] = "1d12";                         update[`repeating_meleeweapons_${newRowId}_meleedamage`] = "8";                         update[`repeating_meleeweapons_${newRowId}_equippedmeleewep`] = "1";                      }                     if (vorpalBladeActive && !vorpalBladeExists) {                         newRowId = generateRowID();                          update[`repeating_meleeweapons_${newRowId}_meleeweaponname`] = "Vorpal Blade";                         update[`repeating_meleeweapons_${newRowId}_meleeweapon`] = "Sword";                         update[`repeating_meleeweapons_${newRowId}_meleeabr`] = "1d8";                         update[`repeating_meleeweapons_${newRowId}_meleedamage`] = "4";                         update[`repeating_meleeweapons_${newRowId}_magicmeleeweaponbonus`] = "3";                          update[`repeating_meleeweapons_${newRowId}_equippedmeleewep`] = "1";                      }                     setAttrs(update, function() {                         // Trigger the manual equip logic with a specific identifier                         setAttrs({                             [`repeating_meleeweapons_${newRowId}_equippedmeleewep`]: "1",                             'source': 'spell' // Custom identifier                         });                     });                 });             });         } else {             getSectionIDs('repeating_meleeweapons', function(ids) {                 const attrsToGet = ids.map(id => `repeating_meleeweapons_${id}_meleeweaponname`);                                  getAttrs(attrsToGet, function(weaponValues) {                     ids.forEach(id => {                         const weaponName = weaponValues[`repeating_meleeweapons_${id}_meleeweaponname`];                         if (weaponName === "Steel Claw") {                             removeRepeatingRow(`repeating_meleeweapons_${id}`);                         }                         if (weaponName === "Vorpal Blade") {                             removeRepeatingRow(`repeating_meleeweapons_${id}`);                         }                     });                 });             });         }     }); }); on("change:repeating_meleeweapons:equippedmeleewep", function(event) {     // Allow the specific sheetworker sources to trigger, prevent others     if (event.sourceType === 'sheetworker' && !(event.sourceAttribute === 'source' && event.sourceValue === 'spell')) {         return;     }     const playerclickedid = event.sourceAttribute.split('_')[2];     getSectionIDs("repeating_meleeweapons", function(ids) {         const fieldnames = [];         ids.forEach(id => fieldnames.push(             `repeating_meleeweapons_${id}_equippedmeleewep`,             `repeating_meleeweapons_${id}_meleeweaponname`,             `repeating_meleeweapons_${id}_meleeweapon`,             `repeating_meleeweapons_${id}_magicmeleeweaponbonus`,             `repeating_meleeweapons_${id}_meleeabr`,             `repeating_meleeweapons_${id}_meleedamage`         ));         getAttrs(fieldnames, values => {             const output = {};             ids.forEach(id => {                 const checkbox = parseInt(values[`repeating_meleeweapons_${id}_equippedmeleewep`]) || 0;                 const meleeweaponname = values[`repeating_meleeweapons_${id}_meleeweaponname`] || "None";                 const meleeweapontype = values[`repeating_meleeweapons_${id}_meleeweapon`] || "None";                 const magicmeleeweaponbonus = parseInt(values[`repeating_meleeweapons_${id}_magicmeleeweaponbonus`]) || 0;                 const meleeabr = values[`repeating_meleeweapons_${id}_meleeabr`] || "0d0";                 const meleedamage = values[`repeating_meleeweapons_${id}_meleedamage`] || "0";                 if (id === playerclickedid) {                     if (checkbox) {                         output.equippedmeleeweaponname = meleeweaponname;                         output.equippedmeleeweapontype = meleeweapontype;                         output.equippedmeleeweaponmagicbonus = magicmeleeweaponbonus;                         output.equippedmeleeweaponabr = meleeabr;                         output.equippedmeleeweapondamage = meleedamage;                     }                 } else if (checkbox) {                     output[`repeating_meleeweapons_${id}_equippedmeleewep`] = 0;                 }             });             setAttrs(output);         });     }); });
1726895930

Edited 1726896042
vÍnce
Pro
Sheet Author
Is this in a Jumpgate game?&nbsp; There's a bug that seems to ignore change events for the odd attributes. <a href="https://app.roll20.net/forum/permalink/12013456/" rel="nofollow">https://app.roll20.net/forum/permalink/12013456/</a> AFAIK this is still a problem.
1726902102
Steve
Pro
Sheet Author
It's CSE compliant, but I don't recall opting into jumpgate or not. I probably did? Any ideas of ways to work around this and avoid the potential issue?
1726903440

Edited 1726903468
GiGs
Pro
Sheet Author
API Scripter
It's hard for us to test this without the HTML, and itr's very complex - it's hard to see solutions without testing. That said, if this isn't a JumpGate problem, I'm sure the complex construction is likely the cause of the issue. At the moment you have a sheet worker with the following structure: getAttrs -&gt; if &gt; getSectionIDs -&gt; getAttrs -&gt; setAttrs -&gt; setAttrs, and another worker that runs on(change:someAttribute') where its setAttrs can include that same someAttribute. These are things I'd be looking at - you can refactor (fancy code-speak to mean jiggle) the code to avoid both these potential issues. Ideally your code should include no more than one each of getAttrs and setAttrs, and one getSectionIDs per repeating section. You say your code "doesn't actually equip it, and it doesn't uncheck the current weapon either" - what code would need to hcange to make those things happen? Purely as an option, for writintg code like this, I'd recommend creating a function like const section_name = (section, id, field) =&gt; `repeating_${section}_${id}_${field}`; Put that at the start of your script block, then you can replace all lines like this: const meleeweaponname = values[`repeating_meleeweapons_${id}_meleeweaponname`] || "None"; with const meleeweaponname = values[section_name('meleeweapons', id, 'meleeweaponname')] || "None"; It saves on typing and I think makes the code easier to read. It doesn't help with your current problem, though. I'd also put the weapons (Steel Claw and Vorpal Sword) in their own object at the start of the code, and extract the values as needed - it'll make it easier to add extra weapons as needed.
1726903634
vÍnce
Pro
Sheet Author
It's an odd bug.&nbsp; Pun intended.&nbsp; When dealing with a handful of attributes as in my test case , it's easy to determine which attributes are odd/even, but I'm not sure how the system actually sorts the attributes (maybe sequentially as they are created, not sure) and it even that could change. I believe the Devs are aware of it (multiple tickets have been submitted), but there hasn't been any public response.
1726904136

Edited 1726904309
GiGs
Pro
Sheet Author
API Scripter
Are we sure this is the same bug? I see structural problems in the code that could easily create async-related issues. Steve said: Any ideas of ways to work around this and avoid the potential issue? I think the only solution at the moment, if you do have a JumpGate bug, is to make sure you aren't using JumpGate (until roll20 irons out the bugs).
Hello, I confirm there's a problem with check boxes and sheetworker : the sheetworker does not listen for each check box status change. I will add that&nbsp; : - the issue is new : the sheets I tested don't behave like they used to - the issue is present in non-jumpgate beta games, which I think is very annoying - the issue is present even if the checkboxes are not in a repeating section
1726943486

Edited 1726943951
GiGs
Pro
Sheet Author
API Scripter
what specifically is the issue?, and how do we reproduce it
Hi GiGs, I think it's a more general issue with sheetworker that doesn't&nbsp; trigger calculations. It was 1st discussed herea month ago :&nbsp; <a href="https://app.roll20.net/forum/post/12013456/it-seems-jumpgate-beta-causes-issues-with-character-sheets" rel="nofollow">https://app.roll20.net/forum/post/12013456/it-seems-jumpgate-beta-causes-issues-with-character-sheets</a> You'll find some code on this thread allowing to reproduce It seems the same issue now happens in non-jumpgate games : <a href="https://app.roll20.net/forum/post/12054927/sheet-triggers-seem-buggy-today#post-12056440" rel="nofollow">https://app.roll20.net/forum/post/12054927/sheet-triggers-seem-buggy-today#post-12056440</a>
1726958473

Edited 1726958602
GiGs
Pro
Sheet Author
API Scripter
Yo're saying the issue affects jumpgate sheets, but as I understand it (maybe I'm wrong?), youre saying it entirely based on this sheet acting weirdly. You might be right, but I don't see that as being required. The code you have provided above could easily have an error in iot that would happen in non-JumpGate sheets. We need to get to the bottom of that before we can say for certain that this is a JumpGate issue. And for that, we need to reproduce it, and for that, we need your HTML and a proper description of the steps needed to reproduce the error. This might be a jumpgate issue, but let's prove it.
GiGs, the bug that seems to ignore change events for the odd attributes has been aknowledged by Roll20 already. 1 month ago they replied to my bug report saying their devs were aware of the bug and would fix it asap, so I think it's proven enough ;) At the time it only affected jumpgate games, and now it has extended to all games, either jumpgate or not. One of the (many I guess) sheet concerned is the Brigandyne community sheet, you can create a game, either jumpgate or not, and see the bug : This sheet has been working for years until about 1 month ago. The code of the sheet is here : <a href="https://github.com/Roll20/roll20-character-sheets/blob/master/Brigandyne/brigandyne.htm" rel="nofollow">https://github.com/Roll20/roll20-character-sheets/blob/master/Brigandyne/brigandyne.htm</a> , the parts involved are the sheetworker (lines 1 to 120) and then the html lines 161 to 465. Just so you know, moving the sheetworker to the bottom of the code, and rewriting the change listeners to lower case din't make a difference.
1726990711

Edited 1726990819
GiGs
Pro
Sheet Author
API Scripter
Fred said: GiGs, the bug that seems to ignore change events for the odd attributes has been aknowledged by Roll20 already. 1 month ago they replied to my bug report saying their devs were aware of the bug and would fix it asap, so I think it's proven enough ;) I understood the first sentence, but I didn't see that your problem only affected odd attributes. We can agree that bug exists, but are we sure it's the bug you've been experiencing? Is your problem only affecting odd rows? If you are experiencing the same bug, that's great for us, because - if not - it looks like it might be a lot of work to track it down and correct it. I just want to be sure!
1726998301
Steve
Pro
Sheet Author
So, while this bug is in play it basically kills my sheet. Therefore I want to work around it somehow, so thinking aloud here, and any suggestions are welcome: I'm thinking that I can have a roll button in place of the checkbox that rolls using the details on its own row only - the only problem with this is that the weapon's magic bonus should apply to the user's Defence score, and if the weapon isn't 'equipped' then it won't know which magic bonus to apply. So maybe instead of a checkbox, I have an action button which applies the equipped status to that row, and that's all it does? Then I need to work around the Main Gauche checkbox - is there a way to populate a select or datalist from the entries on a repeating section elsewhere on the sheet? Otherwise I suppose this could be another action button to set a weapon as Main Gauche Active.
Not sure how I can show you on the forum :) in the image I posted above you see a row of columns, and the sum calculation (circled in red) only triggers one time out of two. Same goes for inputs resulting from checking checkboxes. 1st input won't trigger,&nbsp; 2nd input triggers, 3rd input won't trigger, 4th input triggers and so on.
1726999145

Edited 1726999201
Steve
Pro
Sheet Author
I think Fred's comments have led us down an alternate path? Happy to have you here Fred, but not sure we're having the same error either? It's a maybe on that. I tested my sheet in a new game, Jumpgate not enabled, and I still had the same problems. I tried reverting back to using code from my sheet's 1.2 version, which only did the equip/unequip thing as the spells weren't an implemented feature in that version. It wasn't working - I am getting the same errors from code I know worked, and in a game I know is not Jumpgate enabled.
1727009037

Edited 1727009056
Steve
Pro
Sheet Author
Steve said: ...instead of a checkbox, I have an action button which applies the equipped status to that row, and that's all it does... This works better than the checkbox method - it's far simpler and cleaner, it doesn't have to mess around with unchecking other rows and all of that business. Then I need to work around the Main Gauche checkbox - is there a way to populate a select or datalist from the entries on a repeating section elsewhere on the sheet? Otherwise I suppose this could be another action button to set a weapon as Main Gauche Active. For this, I have created a 'summary' copy of the melee weapons list under the Main Gauche Skill section, and have added an "Equip Offhand" button for each. Just like the other button, it actually works better than the checkbox option...