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

Help with a Sheetworker

Good Day, I am having some trouble getting a sheetworker to work, and have gotten to the point where I am just staring at it with no idea what to do. The goal of the sheetworker is to set basic attributes (strength, dexterity, intelligence, etc.) for a character. It pulls base, bonus, and proficiency values for them, then combines those into two totals: the total value and the actual save that is applied to rolls. The trouble is that the values that it should be setting are simply coming back as 0 no matter what I do. For the most part, any other sheetworkers I have are currently working. The stats to be set are "readonly."  Hopefully it's some minor thing that I have just forgotten about, like the last time I had to ask for help with a sheetworker. In any case, any help or suggestions would be appreciated. /*Attribute Sheetworker */         on("change:str_base change:str_bon change:str_prof change:dex_base change:dex_bon change:dex_prof change:con_base change:con_bon change:con_prof change:int_base change:int_bon change:int_prof change:wil_base change:wil_bon change:wil_prof change:wis_base change:wis_bon change:wis_prof change:cha_base change:cha_bon change:cha_prof", function() {               getAttrs(["STR_BASE","STR_BON","STR_PROF","DEX_BASE","DEX_BON","DEX_PROF","CON_BASE","CON_BON","CON_PROF","INT_BASE","INT_BON","INT_PROF","WIL_BASE","WIL_BON","WIL_PROF","WIS_BASE","WIS_BON","WIS_PROF","CHA_BASE","CHA_BON","CHA_PROF"], function(values) {                 let str_base = parseInt(values.STR_BASE)||0;                 let str_bon = parseInt(values.STR_BON)||0;                 let str_prof = parseInt(values.STR_PROF)||0;                 let dex_base = parseInt(values.DEX_BASE)||0;                 let dex_bon = parseInt(values.DEX_BON)||0;                 let dex_prof = parseInt(values.DEX_PROF)||0;                 let con_base = parseInt(values.CON_BASE)||0;                 let con_bon = parseInt(values.CON_BON)||0;                 let con_prof = parseInt(values.CON_PROF)||0;                 let int_base = parseInt(values.INT_BASE)||0;                 let int_bon = parseInt(values.INT_BON)||0;                 let int_prof = parseInt(values.INT_PROF)||0;                 let wil_base = parseInt(values.WIL_BASE)||0;                 let wil_bon = parseInt(values.WIL_BON)||0;                 let wil_prof = parseInt(values.WIL_PROF)||0;                 let wis_base = parseInt(values.WIS_BASE)||0;                 let wis_bon = parseInt(values.WIS_BON)||0;                 let wis_prof = parseInt(values.WIS_PROF)||0;                 let cha_base = parseInt(values.CHA_BASE)||0;                 let cha_bon = parseInt(values.CHA_BON)||0;                 let cha_prof = parseInt(values.CHA_PROF)||0;                 let str_total_worker = (str_base + str_bon + (str_prof * 5));                 let str_save_worker = Math.floor(((str_total_worker - 50) * 0.5) + (str_prof * pb));                 let dex_total_worker = (dex_base + dex_bon + (dex_prof * 5));                 let dex_save_worker = Math.floor(((dex_total_worker - 50) * 0.5) + (dex_prof * pb));                 let con_total_worker = (con_base + con_bon + (con_prof * 5));                 let con_save_worker = Math.floor(((con_total_worker - 50) * 0.5) + (con_prof * pb));                 let int_total_worker = (int_base + int_bon + (int_prof * 5));                 let int_save_worker = Math.floor(((int_total_worker - 50) * 0.5) + (int_prof * pb));                 let wil_total_worker = (wil_base + wil_bon + (wil_prof * 5));                 let wil_save_worker = Math.floor(((wil_total_worker - 50) * 0.5) + (wil_prof * pb));                 let wis_total_worker = (wis_base + wis_bon + (wis_prof * 5));                 let wis_save_worker = Math.floor(((wis_total_worker - 50) * 0.5) + (wis_prof * pb));                 let cha_total_worker = (cha_base + cha_bon + (cha_prof * 5));                 let cha_save_worker = Math.floor(((cha_total_worker - 50) * 0.5) + (cha_prof * pb));                 setAttrs({                                                 str_total: str_total_worker,                     str_save: str_save_worker,                     dex_total: dex_total_worker,                     dex_save: dex_save_worker,                     con_total: con_total_worker,                     con_save: con_save_worker,                     int_total: int_total_worker,                     int_save: int_save_worker,                     wil_total: wil_total_worker,                     wil_save: wil_save_worker,                     wis_total: wis_total_worker,                     wis_save: wis_save_worker,                     cha_total: cha_total_worker,                     cha_save: cha_save_worker                 });             });         });/* END Attribute Sheetworker */
1601659443
GiGs
Pro
Sheet Author
API Scripter
You have a bunch of these: (str_prof * pb) But pb isnt defined anywhere, so this worker is crashing and cant set any values. What is pb supposed to be?
Ah, that did it. Grabbing pb and defining it fixed the whole thing.  @{pb} is short for proficiency bonus. In a similar vein to 5e, its a bonus value granted to anything one is "proficient" in, except that its a constant value in my system, instead of scaling with level. I just define it on the character sheet so that I can update it everywhere at once if need be. Thank you very much for the assistance.
1601665284
GiGs
Pro
Sheet Author
API Scripter
If you'd like to make the worker more concise, replace everything after the getAttrs line with this:         let stats = ['str', 'dex', 'con', 'int', 'wil', 'wis', 'cha'];         let pb = parseInt(values.pb) || 0;         let output = {};         stats.forEach(stat => {             let base = parseInt(values[`${stat}_BASE`])||0;             let bon = parseInt(values[`${stat}_BON`])||0;             let prof = parseInt(values[`${stat}_PROF`])||0;             let total = base + bon + (prof * 5);             output[`${stat}_total`] = total;             output[`${stat}_save`] = Math.floor((total - 50) * 0.5 + prof * pb);         });         setAttrs(output);     }); }); Rather than repeating the code 7 times for each stat, you can do a loop through the 7 stats and just write the main code once.
Just wanted to post a bit of a late thanks for that last reply with the forEach loop. Although it ran, it initially resulted in setting all values to 0. It took me a week of practice with other parts of my sheetworkers, but I eventually realized that it was probably pulling the default values set for each stat, and not the actual stat. After playing around with it a bit and confirming that, I learned that the problem had to do with capitalizing. The array "stats" has lower case words, but I pulled all the stats in as uppercase. So, when looking for "base" for example, it was looking for str_BASE, but I had STR_BASE. After realizing and fixing capitalization errors, I managed to get it working properly.  Being able to use forEach loops in my sheetworkers will definitely help clean up the code a lot, since I have a lot of areas with repeated and very similar formulas being run.
1602447207
GiGs
Pro
Sheet Author
API Scripter
Intriguing. There's advice on the wiki which is very good advice: in your html, make all of your attribute names entirely lower case. You sidestep issues like this. If you do this, any characters with attributes in different case will keep their values. If you change, for instance value="attr_STR_BASE"  to  value="attr_str_base"  , the stats will keep their values - at the sheet and macro level, roll20 ignores case. It's only in some very specific situations in sheet workers and API coding where case matters and you might have stumbled across one.