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 for inclusion in sum

I have a repeating section that contains a number field and a separate field outside that displays the sum of all these fields. What I want to do now is add a checkbox to the repeating section such that when the checkbox is ticked then the corresponding number field is not  included in the total sum. Is this doable? The sheetworker code for the sum is:   on('change:repeating_gear:gupkeep remove:repeating_gear', function() { repeatingSum('equup',"gear",'gupkeep','bpupkeep','rupkeep'); }); This has the effect of recalculating the equup attribute (the total) whenever an item from the gear repeating section is removed or has the gupkeep attribute changed. It also adds the bpupkeep and rupkeep attributes (which are both outside the repeating section) to the total. What I need is for the gupkeep attribute to be ignored if and only if the corresponding checkbox is ticked.
1606676831
Andreas J.
Forum Champion
Sheet Author
Translator
Rich K. said: What I need is for the gupkeep attribute to be ignored if and only if the corresponding checkbox is ticked. You could create a separate attribute(lets call it realgupkeep ) to track the value of gupkeep  that will be counted in the repeating section. You then create a separate sheetworker that updates realgupkeep based on the value of gupkeep , but set it to zero if the checkbox is checked. Then replace gupkeep  in the RepeatSum() with realgupkeep. This could probably be made with a single sheetworker, but this workaround should work with RepeatSum() .
set it to zero if the checkbox is checked Sounds good. How do I do the 'if' part?
1606685396
Andreas J.
Forum Champion
Sheet Author
Translator
I'm not good enough on this to give you an example straight away, but this is in the simpler end of things, the wiki examples should be enough for you to figure out the exact thing. My example assumes you'll add  a checkbox with the name ignoregupkeep that has a value of 1 to the repeating section. The new sheetworker section would be something along these lines: on('change:repeating_gear:gupkeep change:repeating_gear:ignoregupkeep', function() { getAttrs(" repeating_gear:gupkeep repeating_gear:ignoregupkeep"{ var realgupkeep = gupkeep; if (ignoregupkeep === 1){ realgupkeep = 0; } setAttrs{ countgupkeep = realgupkeep } )}; }); Read up on the wiki examples to check the exact format for these, or someone else to give you the exact thing.
1609108888

Edited 1609109275
GiGs
Pro
Sheet Author
API Scripter
Rich K. said: I have a repeating section that contains a number field and a separate field outside that displays the sum of all these fields. What I want to do now is add a checkbox to the repeating section such that when the checkbox is ticked then the corresponding number field is not  included in the total sum. Is this doable? The sheetworker code for the sum is:   on('change:repeating_gear:gupkeep remove:repeating_gear', function() { repeatingSum('equup',"gear",'gupkeep','bpupkeep','rupkeep'); }); This has the effect of recalculating the equup attribute (the total) whenever an item from the gear repeating section is removed or has the gupkeep attribute changed. It also adds the bpupkeep and rupkeep attributes (which are both outside the repeating section) to the total. What I need is for the gupkeep attribute to be ignored if and only if the corresponding checkbox is ticked. That's an interesting problem. Andreas's solution is a good one. You can also use repeatingSum directly without creating an extra attribute, though I'd normally create a custom function for situations like this. What is the attribute name of the checkbox? I've named it checkbox  here, replace that with the actual name of the checkbox. Also make sure that the checkbox input has value="1". Then in the sheet worker you grab the checkbox value, and subtract it from 1, so when the checkbox is checked, it has an actual value of 0, and unchecked it has a value of 1. You can then multiply the checkbox by the gupkeep stat, so when the checkbox is checked, that row will equal zero. Something like this: on('change:repeating_gear:gupkeep  remove:repeating_gear change:repeating_gear:checkbox', function() {     getAttrs(['checkbox'], values => {         const check = 1- (parseInt(values.checkbox) || 0);         repeatingSum('equup',"gear",[check,'gupkeep'],'bpupkeep','rupkeep');     });  }); Just change each checkbox  to whatever the checkbox attribute name is.