In that case, you just need to copy the first script on that page (dont edit it), and then add a sheet worker, like so: /* ===== PARAMETERS ==========
destination = the name of the attribute that stores the total quantity
section = name of repeating fieldset, without the repeating_
fields = the name of the attribute field to be summed
can be a single attribute: 'weight'
or an array of attributes: ['weight','number','equipped']
multiplier (optional) = a multiplier to the entire fieldset total. For instance, if summing coins of weight 0.02, might want to multiply the final total by 0.02.
*/
const repeatingSum = (destination, section, fields, multiplier = 1 ) = > {
if ( ! Array . isArray (fields)) fields = [fields];
getSectionIDs (`repeating_${section}`, idArray = > {
const attrArray = idArray. reduce ( (m,id) = > [...m, ...(fields. map (field = > `repeating_${section}_${id}_${field}`))],[]);
getAttrs (attrArray, v = > {
console. log ( "===== values of v: " + JSON. stringify (v) + " = = = = = ");
// getValue: if not a number, returns 1 if it is 'on' (checkbox), otherwise returns 0..
const getValue = (section, id,field) = > parseFloat (v[`repeating_${section}_${id}_${field}`]) | | (v[`repeating_${section}_${id}_${field}`] = = = 'on' ? 1 : 0 );
const sumTotal = idArray. reduce ((total, id) = > total + fields. reduce ((subtotal,field) = > subtotal * getValue (section, id,field), 1 ), 0 );
setAttrs ({[destination]: sumTotal * multiplier});
});
});
}; on ( 'change:repeating_gear remove:repeating_gear' , function () {
repeatingSum ( " encumbrance_total " ,"gear","gearitem");
}); and replace encumbrance_total with the name of the attribute where you want the total to be saved.