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

Counting Specific Skills in Repeating Section

1668753974
Lillian W.
Pro
Sheet Author
In my Heavy Gear 4e playtest game  each skill comes from one of 20 domains, a broad area in which skills fall under, eg one of my players has "ambushes" skill in the Awareness domain, another has "Dirty Fighting" under the Melee domain. If a character has a certain amount of skill points in a domain they get bonuses like rerolls etc.  I want to do some sheetworker script to update an attribute eg domain_expertise_athletics, to be the total skill levels in that domain. Ive tried messing around with repeatingSum but I cant seem to get things to work.  This is the code for the repeating skills.   <fieldset class="repeating_skills"> <div class="sheet-3colrow"> <div class="sheet-col"> <button type="roll" name="roll_skill" value="/em uses @{domain_select} @{skill_name} @{skill_level} [[@{skill_level}d6>5]]"></button> <input type="text" name="attr_skill_name" value=""> </div> <div class="sheet-col"> <select name="attr_domain_select"> <option value="1" selected>Athletics</option> <option value="2">Awareness</option> <option value="3">Business </option> <option value="4">Craft </option> <option value="5">Culture </option> <option value="6">Electronic Warfare</option> <option value="7">Electronics </option> <option value="8">Gunnery</option> <option value="9">Hard Science </option> <option value="10">Institutions </option> <option value="11">Investigation </option> <option value="12">Mechanics </option> <option value="13"> Medicine </option> <option value="14">Melee </option> <option value="15">Influence </option> <option value="16">Pilot </option> <option value="17"> Showmanship </option> <option value="18">Social Science </option> <option value="19"> Survival </option> <option value="20">Tactics </option> </select> </div> <div class="sheet-col"> <input type="number" name="attr_skill_level" value=" " min="0" max="5"> <input type="checkbox" name="attr_skill_xp" value="1"> <input type="number" name="attr_skill_xp_stored" value="0"> </div> </div> </fieldset> I would imagine the code goes something like this <script type="text/worker"> const domains = ['athletics','awareness','business','craft','culture','electronicwarfare','electronics','gunnery','hardscience','institutions','investigation','mechanics','medicine','melee','influence','pilot','showmanship','socialscience','survival','tactics']; on("change:repeating_skills sheet:opened",function(){ //make array expertise[] //add repeating_skill_level to expertise[repeating_skill_domain_select] setAttrs({ domains.forEach(domains => { expertise[domains]: ["domain_expertise_" + domains] }); }); });  Any help would be appreciated
1668770957

Edited 1668771171
Oosh
Sheet Author
API Scripter
The repeatingSum function is more set up for 'columns', so a field in every repeating row getting summed to a total somewhere. It won't work without some tinkering here, since you've got the same field in each row going to a different total depending on another field value. I haven't touched sheets for a long time, but I think something like this should do it (thoroughly untested): const calculateDomainTotals = () => { // get section row ids getSectionIDs('skills', (idArray) => { // grab attributes const requiredAttributes = [ ...idArray.map(id => `repeating_skills_${id}_domain_select`), ...idArray.map(id => `repeating_skills_${id}_skill_level`), ]; getAttrs(requiredAttributes, (attributeValues => { // go through each row, grab the domain from one field and assign the skill value to the output object/domain name const totals = idArray.reduce((output, id) => { const domain = attributeValues[`repeating_skills_${id}_domain_select`]; output[`domain_expertise_${domain}`] = (output[domain] || 0) + (attributeValues[`repeating_skills_${id}_skill_level`] || 0); return output; }, {}); // the output from the reduce function should be right to go straight to setAttrs I think? setAttrs(totals); })); }); }