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

Need a little sheetworker help

1685410377

Edited 1685410426
vÍnce
Pro
Sheet Author
TIA Info: Skills have a Level 0-6 (I may change the upper limit, but for the sake of simplicity it's 0-6 for now) I want to total the number of Skills for each Level as well as a grand total. (again, I might not use this but it's easy enough to keep for the time being) The code below seems to function down to this line; const level = +values[skillName(field)] || 0; but level is always 0 in the log and it doesn't seem to loop through the other skills.  I'm sure there are numerous issues here since I modified an existing bit of code from (hmm, GiGs of course) Any suggestions?  Thanks /* Skill Rank Totals */ const skillName = (field) => `${field}`; const skills = [ 'animal_handling', 'crafting', 'endurance', 'healing', 'insight', 'lore', 'manipulation', 'marksmanship', 'melee', 'might', 'move', 'performance', 'scouting', 'sleight_of_hand', 'stealth', 'survival', ]; on( 'change:animal_handling change:crafting change:endurance change:healing change:insight change:lore change:manipulation change:marksmanship change:melee change:might change:move change:performance change:scouting change:sleight_of_hand change:stealth change:survival', (eventInfo) => { clog(`Change Detected: ${eventInfo.sourceAttribute}`); const fields = []; // create an array of the skill names skills.forEach((field) => { fields.push(skillName(`${skills}`)); clog(`field: ${field}`); }); getAttrs(fields, (values) => { clog(`Skills:${skills}`); const output = {}; const statsArray = ['skill_level1', 'skill_level2', 'skill_level3', 'skill_level4', 'skill_level5', 'skill_level6', 'skill_levels']; // loop through statsArray array, rename to match output attribute and set to 0 statsArray.forEach((stat) => { output[`${stat}_total`] = 0; }); // loop through each attribute in the array and grab the value skills.forEach((field) => { const level = +values[skillName(field)] || 0; clog(`Level:${level}`); if (level === 1) { output.skill_level1_total += level; } else if (level === 2) { output.skill_level2_total += level; } else if (level === 3) { output.skill_level3_total += level; } else if (level === 4) { output.skill_level4_total += level; } else if (level === 5) { output.skill_level5_total += level; } else if (level === 6) { output.skill_level6_total += level; } output.skill_levels_total += level; }); setAttrs(output); }); } );
1685415236
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
So, your skillName function isn't really necessary. There's no difference between this: +values[skillName(field)] || 0; and +values[field] || 0; If you were going to be concatenating values together, then there might be a reason to use a function to assemble it, but for that I'd recommend storing the assembled value in a variable, and then putting the variable in the field call instead of doing the function call directly in the field call. All of that said, it's not your problem, other than that it's helping to mask the actual problem. Your actual problem is on line 28: const fields = []; // create an array of the skill names skills.forEach((field) => { fields.push(skillName(`${skills}`));//Line 28 clog(`field: ${field}`); }); You are passing the array of skills to your skillName function instead of the individual fields to assemble your fields array. There is actually a better way to do this though: const fields = [...skills]; That will replace your entire skills.forEach piece there. With that change, your existing code should work.
1685420520
vÍnce
Pro
Sheet Author
That works of course.  Thank you very much Scott.