SOLVED! (Thanks to the amazing GiGs) See: <a href="https://app.roll20.net/forum/permalink/7216689/" rel="nofollow">https://app.roll20.net/forum/permalink/7216689/</a> Sorry to be of bother to anyone, but as a complete newb to sheet worker scripts I am trying to help a friend of mine with simplifying the encumberance calculations for his Mutant Year: Zero session by having them automatically calculate. One part of the Gear is in a Repeating format, so I used "RepeatingSum" . However, I need to include a few values to this calculation that are not part of the repeating section... namely the first row of the inventory is just a simple row with regular attributes (gear-name, gear-encumberance, gear-amount, gear-carried). Then I am trying to include the food and water supply (even though I suppose that's not strictly necessary) via the attributes "grub" and "water" which each count as 0.25 units of weight. I studied the code for a few hours and went to modifying it, but I am very much of a beginner at this and it's rather advanced, so I probably just broke something. So naturally, when I reload and try it out, the encuberance value isn't updating. So I assume I must have commited some excruciating programming sin in so crudely modifying GiGs example script, so I'm sorry for that! x.x I already thank anyone attempting to help, although I am sorry if I'm wasting your time with this! Here are the atrocities I have commited on RepeatingSum to have it include a couple of nonrepeating attributes: 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) +" =====");
const getValue = (section, id,field) => parseFloat(v[`repeating_${section}_${id}_${field}`], 10)||1; // default value of 1, so any faulty value inputs are ignored and the calculation still works.
const sumTotal = idArray.reduce((total, id) => total + fields.reduce((subtotal,field) => subtotal * getValue(section, id,field),1),0);
var almostdone = sumTotal * multiplier;
});
});
getAttrs(["gear-amount", "gear-carried", "grub", "water"], almostdone {
var onegearmulti = parseFloat(values.gear-carried, 10)||1;
var onegear = values.gear-amount * onegearmulti;
var grub25 = values.grub * 0.25;
var water25 = values.water * 0.25;
setAttrs({[destination]: almostdone + onegear + grub25 + water25
});
});
});
}; And this is the function which calls the repeatingSum: on('change:repeating_gear remove:repeating_gear change:grub change:water change:gear-carried change: gear-amount', function() {
repeatingSum("encumberance","gear",["gear-encumberance", "gear-amount", "gear-carried"]);
}); Edit: Alright I toyed around a bit more and even the standalone RepeatingSum script only outputs the number of items in the repeating field and doesn't interact with other values I input at all. ;_;