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

Checkbox outside of Repeating Fields

1588973907

Edited 1588974130
Eli N.
Pro
Compendium Curator
So I have a checkbox outside of a repeating field that is not working great for me  Here is the repeating field             <div class="sheet-row sheet-skill-row">                 <fieldset class="repeating_skill">                     <div class="sheet-col-15-24 sheet-vert-middle"><input type="text" name="attr_skillname"/></div>                     <div class="sheet-col-1-6 sheet-vert-middle"><input type="number" name="attr_mastery" value="0"/></div>                     <input type="hidden" name="attr_skillname_dice" value="[[d100]] Skill: [[@{mastery}]]" />                     <div class="sheet-col-5-24 sheet-vert-middle"><button class="sheet-skill-roll" type='roll' name='roll_skill' value='@{character_name} makes a @{skillname} skill check\n\nRoll :@{skillname_dice}'>Check</button></div>                 </fieldset>             </div> Here are the worker scripts I have tried  on("change:skill_dice_switch sheet:opened", function() { getAttrs(["skill_dice_switch"], function(values) { var check = parseInt(values.skill_dice_switch) || 0; var diceRS = check ? "[[1d100+@{repeating_skill_mastery}]] vs Opposing Roll" : "[[d100]] Skill: [[@{repeating_skill_mastery}]]"; setAttrs({ repeating_skill_skillname_dice: diceRS }); }); }); on("change:skill_dice_switch sheet:opened", function() { getAttrs(["skill_dice_switch"], function(values) { var check = parseInt(values.skill_dice_switch) || 0; var diceRS = check ? "[[1d100+@{mastery}]] vs Opposing Roll" : "[[d100]] Skill: [[@{mastery}]]"; setAttrs({ repeating_skill_skillname_dice: diceRS }); }); }); on("change:skill_dice_switch sheet:opened", function() { getAttrs(["skill_dice_switch"], function(values) { var check = parseInt(values.skill_dice_switch) || 0; var diceRS = check ? "[[1d100+@{mastery}]] vs Opposing Roll" : "[[d100]] Skill: [[@{mastery}]]"; setAttrs({ skillname_dice: diceRS }); }); });
1588974172
Andreas J.
Forum Champion
Sheet Author
Translator
What is the checkbox supposed to do, and how is the section supposed to act based on the checkbox?
1588975807
Eli N.
Pro
Compendium Curator
Oh right duh, its supposed to switch from rolling a 1d100 and comparing to the skill level and rolling a 1d100 and adding it to the skill level. 
1588976300
Eli N.
Pro
Compendium Curator
I have it working for every non-repeating section (the universal skills every character sheet has) 
1588978510

Edited 1588979471
GiGs
Pro
Sheet Author
API Scripter
If the checkbox is outside the repeating section, and you want to change the contents of a repeating section, you have to use the getSectionIDs function.  The important thing to understand, is the repeating section may contain multiple rows. So to address every row in the sheet, you need an attribute name that contains the repeatign section, the row id, and the actual name. Since you want to change the attribute on  every row of the repeating section, you code has to loop through the rows and change each one. Here's a worker that should do the trick. on("change:skill_dice_switch sheet:opened", function() {     getSectionIDs('repeating_skill', function(idarray) {         getAttrs(["skill_dice_switch"], function(values) {             var check = parseInt(values.skill_dice_switch) || 0;             var diceRS = check ? "[[1d100+@{mastery}]] vs Opposing Roll" : "[[d100]] Skill: [[@{mastery}]]";             // create a variable to hold the attribute names and their value             const output = {};             // now loop through every row id, and update the skillname_dice attribute on that row             idarray.forEach(id => {                 output[`repeating_skill_${id}_skillname_dice`] = diceRS;             });             // update the stats on the sheet             setAttrs(output);         });     }); });
1588978698

Edited 1588978706
GiGs
Pro
Sheet Author
API Scripter
Note: if you have skill_dice_switch affecting multiple stats on the same sheet, you should put all the changes in one worker. Just add each to the above worker like so output['NAME GOES HERE INSIDE THESE QUOTES'] =  diceRS; Just add that imemdiately after the output = {} line.
1588983239
Eli N.
Pro
Compendium Curator
Even if they are switching to different stats?
1588983338
Eli N.
Pro
Compendium Curator
would it be  on("change:skill_dice_switch sheet:opened", function() {     getSectionIDs('repeating_skill', function(idarray) {         getAttrs(["skill_dice_switch"], function(values) {             var check = parseInt(values.skill_dice_switch) || 0;             var diceRS = check ? "[[1d100+@{mastery}]] vs Opposing Roll" : "[[d100]] Skill: [[@{mastery}]]";             var dice = check? [Stuff]             // create a variable to hold the attribute names and their value             const output = {};             // now loop through every row id, and update the skillname_dice attribute on that row             idarray.forEach(id => {                 output[`repeating_skill_${id}_skillname_dice`] = diceRS;                   output[`other name`] = dice;             });             // update the stats on the sheet             setAttrs(output);         });     }); });
1588983774

Edited 1588983824
GiGs
Pro
Sheet Author
API Scripter
No, the forEach loop is only for the repeating section. your non-repeating attributes dont go in there. Post your other sheet workers, and I can tell you how to incorporate them. Without specifics my suggestions can easily be misunderstood. But it would be probably more like on("change:skill_dice_switch sheet:opened", function() {     getSectionIDs('repeating_skill', function(idarray) {         getAttrs(["skill_dice_switch"], function(values) {             var check = parseInt(values.skill_dice_switch) || 0;             var diceRS = check ? "[[1d100+@{mastery}]] vs Opposing Roll" : "[[d100]] Skill: [[@{mastery}]]";             var dice = check? [Stuff];            const output = {};             output[`other name`] = dice;             idarray.forEach(id => {                 output[`repeating_skill_${id}_skillname_dice`] = diceRS;             });             setAttrs(output);         });     }); });
1588985425
Eli N.
Pro
Compendium Curator
if you treat the 'repeating" as just a regular old skill to swap and not a repeating section then I was doing it the same aka on("change:skill_dice_switch sheet:opened", function() {         getAttrs(["skill_dice_switch"], function(values) {             var check = parseInt(values.skill_dice_switch) || 0;             var diceRS = check ? "[[1d100+@{repeating_skill_mastery}]] vs Opposing Roll" : "[[d100]] Skill: [[@{repeating_skill_mastery}]]";         setAttrs({             repeating_skill_skillname_dice: diceRS         });     }); });
1588985992
GiGs
Pro
Sheet Author
API Scripter
This syntax repeating_skill_skillname_dice: diceRS only works when the attribute that triggers the worker is on the same row of the repeating section as the attribute to be changed. In that case you dont need to supply a row id, because both attributes have the same row id. But also you can only change one row at a time with this syntax. When you have an attribute outside the section, that is changing all the rows of a repeating section, you need to use getSectionIDs to get all the row ids, so roll20 can update each of them. Even if there's only one row, it still needs a row id.