Hello All! I've been been grappling with this for way too long...and getting no where. I've scoured the forums and haven't found an answer yet. I have a sheet that I'm working on that has 37 skills in a Static section. Each of the skills has a checkbox. I want to total the number of checkboxes that have been checked and put that total in a span linked to a hidden variable. For testing purposes, I tried to do this step by step with only 3 skills. I was able to get to work without using a loop. on("sheet:opened", function() { getAttrs(["accounting", "bullshit", "charm"], function(values) { let ascore = parseInt(values.accounting) || 0; let bscore = parseInt(values.bullshit) || 0; let cscore = parseInt(values.charm) || 0; let total = ascore + bscore + cscore; console.log(total); setAttrs({ iskill_total: total }); }); }); So my next step was trying to get this to work using a loop of an external loop inspired by this code from the Universal Sheetworkers Page: const stats = [ 'str' ,'dex','con',' int ','wis','cha'];
stats. forEach ( function (stat) {
on ( "change:" + stat + " sheet:opened" , function () {
getAttrs ([stat], function (values) {
const stat_score = parseInt (values[stat]) | | 0 ; // this extracts the stat, and assumes a stat score of 0 the stat is not recognised as a number.
const stat_modifier = Math. floor (stat_score / 2) -5; // this gives a +0 at 10-11, and + / 1 for 2 point difference.
setAttrs ({
[stat + '_mod' ]: stat_modifier
});
});
});
}); So, I just couldn't get it to work. I tried a bunch of different options...but the problem is I want a running total. I tried some += excitement, but that didn't work. Is there some sort of function that will just total all the values in an array? Or is there some way to initialize an interim number to 0 outside of the for loop, pass that into the for function, have each skill set the Attribute of that number passed in to itself + the skill's value. Or is there a different way to do it? I notice that Aaron made a sheetworker for repeating sections...but I'm looking for a way to do this in non-repeating sections. There must be some sort of fairly easy way to do this. I accidentally pulled an all-nighter trying to work this out. And I really should go to bed. If I can get this worked out, then I can move onto the next part of the character sheet project...I'm looking forward to this being my first character sheet that I submit to the repository. But I've got to figure this out first. Thanks for any help y'all might have!