First thing: your agriculture skill is disabled, so the sheet worker cant change its value. You need to change the readonly. Second, unrelated: you can reduce all those getmods to one function: const getMod = (set, score, mod) => (score> 20) ? 4 : set.findIndex(check => check >= score) - mod;
const mods_def = [2, 4, 7,10, 12, 15, 18,20]; const wisdom_defense_mod = getMod(mods_def, wistot, 4);
const mods_save = [3,5,7,9, 13, 15, 18,20];
const mental_save_bonus = getMod(mods_save, wistot, 4);
const mods_init = [2,3,4,7,10,12,15,18,20];
const wisdom_initiative_mod = -1 * getMod(mods_init, wistot, 7);
const mods_ft = [3,6,9,12,15,18,21,22];
const fatigue_wis = -1 * getMod(mods_ft, wistot, 3); or even better const getMod = (set, score, mod) => (score> 20) ? 4 : set.findIndex(check => check >= score) - mod;
const mods = {
def: [2, 4, 7,10, 12, 15, 18,20],
save: [3,5,7,9, 13, 15, 18,20],
init: [2,3,4,7,10,12,15,18,20],
ft: [3,6,9,12,15,18,21,22]
};
const wisdom_defense_mod = getMod(mods.def, wistot, 4);
const mental_save_bonus = getMod(mods.save, wistot, 4);
const wisdom_initiative_mod = -1 * getMod(mods.init, wistot, 7);
const fatigue_wis = -1 * getMod(mods.ft, wistot, 3); Okay on to your issue. You seem to be saving wis to the checkbox values. You shouldnt be doing that. You shouldnt be altering that through the sheet worker at all. But also, you need to check the value of each skill's checkbox. To do that you must get those values into the sheet worker, by adding them to getAttrs. You should probably also have them in the on(change) line, so that the value can be updated when a player checks or unchecks the box. To achieve this, I would recommend creating two arrays inside an object before the sheet worker that looks like: const skills = { wisdom_universal: ['animal_husbandry', 'etc'], wisdom_checkbox: ['agriculture', 'more here'] }; Just add the rest of the skills - each in quotes, and separated by a comma. You need two arrays: one for all the wisdom skills that are universal, and one for all those that need the checkbox checked. side note: i assume administra c tion is a typo. Now we have those, we can loop through them in various ways. For instance, to add the checkbox values to the on(changes) line you can build a string of them all with one line of code: const wisChanges = skills.wisdom_checkbox.map(skill => `change:skill_${skill}_checkbox`).join(' '); map is a function that takes an array and does something to every item in that array. In the above, we are taking each skill in the checkboxes list, and adding "change:skill_" and "_checkbox" to its value. Then joining it into a string separated by spaces. We can use that like so: on(`change:wisdom change:wisdom_fractional ${wisChanges} sheet:opened`, function() { You can do a similar process for the getAtrrs line. Here we keep it as an array, so we dont need the join at the end: const wisAttrs = skills.wisdom_checkbox.map(skill => `skill_${skill}_checkbox`); This allows use to use: getAttrs(['wisdom','wisdom_fractional', ...wisAttrs], function(values) { The ... before the name of wisAttrs array is called the spread operate. It spreads out an array into its items, so that drops each skill full name into getAttrs where we need it. So now the values object contains all the checkbox values for wisdom skills. And this sheet worker will update whenever any checkbox is clicked, or the wisdom value changes. To set the scores inside the sheet worker, we are going to loop through both the wisdom skills arrays above. First we create an object to hold the final values like so: const output = {}; Then we loop through the universal array like so skills.wisdom_universal.forEach(skill => { output[`skill_${skill}_untrained`] = wis; }); This takes the wisdom_universal array, and gets every skill name, adds "skill_" and "_untrained" to it, thus building a proper attribute named. It then adds an entry with that name to output , and sets its value to wis. Once that loop runs, we have avariable that contains all the universal skills and their new values. We are going to do the same for the checkbox array. But this time we need to check if the checkbox is checked, and only enter the wis value if it is. But we also need to handle what happens if it is not checked. Imagine a player checks the box - that skill gains a value equal to wis. Then they uncheck it. If the worker does nothing, the skill will still have the value. So we need to reset the value when unchecked. here's a loop that does exactly that. skills.wisdom_checkbox.forEach(skill => { const check = int(values[`skill_${skill}_checkbox`]); if(check) { output[`skill_${skill}_untrained`] = wis; } else { output[`skill_${skill}_untrained`] = 0; } }); I assume the value you want when unchecked is 0. You can change that to whatever it should be. And then we have to save the new values, which is simple enough: setAttrs(output); Putting all that together (with a few name changes for clarity): const getStatMod = (set, score, mod) => (score> 20) ? 4 : set.findIndex(check => check >= score) - mod; const stat_mods = { def: [2, 4, 7,10, 12, 15, 18,20], save: [3,5,7,9, 13, 15, 18,20], init: [2,3,4,7,10,12,15,18,20], ft: [3,6,9,12,15,18,21,22] };
const skills = { wisdom_universal: ['animal_husbandry', 'etc'], wisdom_checkbox: ['agriculture', 'more here'] }; const wisChanges = skills.wisdom_checkbox.map(skill => `change:skill_${skill}_checkbox`).join(' '); const wisAttrs = skills.wisdom_checkbox.map(skill => `skill_${skill}_checkbox`); on(`change:wisdom change:wisdom_fractional ${wisChanges} sheet:opened`, function() { getAttrs(['wisdom','wisdom_fractional', ...wisAttrs], function(values) { const wis = int(values.wisdom); const wisfrac = int(values.wisdom_fractional); let wistot = wis + wisfrac*.01; console.log(wistot);
const output = {}; output.wisdom_defense_mod = getStatMod(stat_mods.def, wistot, 4); output.mental_save_bonus = getStatMod(stat_mods.save, wistot, 4); output.wisdom_initiative_mod = -1 * getStatMod(stat_mods.init, wistot, 7); output.fatigue_wis = -1 * getStatMod(stat_mods.ft, wistot, 3);
skills.wisdom_universal.forEach(skill => { output[`skill_${skill}_untrained`] = wis; }); skills.wisdom_checkbox.forEach(skill => { const check = int(values[`skill_${skill}_checkbox`]); if(check) { output[`skill_${skill}_untrained`] = wis; } else { output[`skill_${skill}_untrained`] = 0; } }); setAttrs(output); }); }); A few things to note: I moved the getMod function and the stat_mods outside the sheet worker. I am assuming to will also have a similar sheet worker for the other stats, and this allows you to use the same code for each. No need to write it again in each worker. I also named the skills variable the way I did so you can just put the arrays for the other stats in there as well, and then use basically the same sheet worker code for the other stats. I also put the four special stats in a different format: no need to individually define them, when we can just add them directly to the output object. Hope this helps!