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

A question about the RepeatingSum function

1666089317

Edited 1666089379
Fred
Pro
Hello ! I try to get the repeating sum function explained here <a href="https://wiki.roll20.net/RepeatingSum" rel="nofollow">https://wiki.roll20.net/RepeatingSum</a> to work in my custom sheet, to no avail. Before going any further, I wanted to make sure if I understand properly : in the code below there are "field s " and "field". Is "field" to be replaced by the attibute of the field to be summed or left as it is ? /* ===== 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' &nbsp;? 1 &nbsp;: parseFloat (v[`repeating_${section}_${id}_${field}`]) | | 0 ; const commonMultipliers = (fields. length &lt; = destinations. length )&nbsp;? []&nbsp;: 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 ); }); setAttrs (output); }); }); };
1666100403
Kraynic
Pro
Sheet Author
Note that right above that code block on the wiki, it says to "Include the function with no changes".&nbsp; You simply copy/paste this part as is into the script block for your sheet.&nbsp; Then you use the example bits of code below that in the wiki article to build the bits that interact directly with your sheet. You can see a fairly simple use of this for summing inventory weight and summing skill modifiers in one of my sheets.&nbsp; You can find it starting at line 2117: <a href="https://github.com/Roll20/roll20-character-sheets/blob/master/Palladium%20Fantasy%201E/palladium_fantasy_1e.html" rel="nofollow">https://github.com/Roll20/roll20-character-sheets/blob/master/Palladium%20Fantasy%201E/palladium_fantasy_1e.html</a>
1666131955

Edited 1666131983
Fred
Pro
LOL ! No wonder I couldn't get it to work, I was wrong from the 1st step ! Thank you very much Kraynic, with your help and inspiration from your sheet I got mine to work :)