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

Problem with sum of repeating rows

1618338718

Edited 1618338902
.Hell
Sheet Author
I want to conditionally sum a value in a repeating section. I used <a href="https://wiki.roll20.net/RepeatingSum#Conditional_Sums_.28e.g._using_a_Checkbox.29" rel="nofollow">https://wiki.roll20.net/RepeatingSum#Conditional_Sums_.28e.g._using_a_Checkbox.29</a> as a base but cannot get it to work
1618339062
.Hell
Sheet Author
on('change:repeating_armors remove:repeating_armors', function() { repeatingSum("armor_total", "armors",["armorvalue","armorworn"]); }); /* ===== PARAMETERS ========== destinations = the name of the attribute that stores the total quantity can be a single attribute, or an array: ['total_cost', 'total_weight'] If more than one, the matching fields must be in the same order. section = name of repeating fieldset, without the repeating_ fields = the name of the attribute field to be summed destination and fields both can be a single attribute: 'weight' or an array of attributes: ['weight','number','equipped'] */ const repeatingSum = (destinations, section, fields) =&gt; { if (!Array.isArray(destinations)) destinations = [destinations.replace(/\s/g, '').split(',')]; if (!Array.isArray(fields)) fields = [fields.replace(/\s/g, '').split(',')]; getSectionIDs(`repeating_${section}`, idArray =&gt; { const attrArray = idArray.reduce((m, id) =&gt; [...m, ...(fields.map(field =&gt; `repeating_${section}_${id}_${field}`))], []); getAttrs([...attrArray], v =&gt; { const getValue = (section, id, field) =&gt; v[`repeating_${section}_${id}_${field}`] === 'on' ? 1 : parseFloat(v[`repeating_${section}_${id}_${field}`]) || 0; const commonMultipliers = (fields.length &lt;= destinations.length) ? [] : fields.splice(destinations.length, fields.length - destinations.length); const output = {}; destinations.forEach((destination, index) =&gt; { output[destination] = idArray.reduce((total, id) =&gt; total + getValue(section, id, fields[index]) * commonMultipliers.reduce((subtotal, mult) =&gt; subtotal * getValue(section, id, mult), 1), 0); }); console.log(output); setAttrs(output); }); }); };
1622537834
GiGs
Pro
Sheet Author
API Scripter
Did you find a solution for this? It looks to me like the HTML for your armorworn attribute is correct. Try it with value="1" instead. PS: It's always best to post code as text, not a screenshot, so people can copy it and edit it when replying, to show you solutions easier.
1622560681
.Hell
Sheet Author
Yeah I found a solution for it. I tried posting it as code first, but the forum didnt allow it.
1622618513
GiGs
Pro
Sheet Author
API Scripter
You found a solution? *inserts "my work is done here." "But you didn't do anything!" meme.*
1622637579
.Hell
Sheet Author
Yeah, Roll20 is not the best forum and I had a hard time finding all this stuff again. Due to no answer for a long time in this topic I recreated this issue in another sub-forum where the solution can be found: <a href="https://app.roll20.net/forum/post/9992186/problem-with-sum-of-repeating-rows" rel="nofollow">https://app.roll20.net/forum/post/9992186/problem-with-sum-of-repeating-rows</a>
1622641701
GiGs
Pro
Sheet Author
API Scripter
I'm a bit puzzled by the pointer-events requirement, I don't shy why this necessary - unless its you way to block players editing the cell. The easiest way is to replace disabled="true" with readonly, in the HTML - that stops players editing it. For the record, disabled attributes cant be changed by sheet workers - that's why you cant use disabled.