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 .
×

Simple Looped Worker from UniversalSheetWorkers page-- breaks my other Sheet Workers, won't work.

Hello.  I'm very new to Roll20 and coding.  Looking through example of code and having trouble with the example of a looped sheet worker.  Every time I add it to my sheet worker section, it doesn't work and breaks the functionality of my other sheet workers.  I have copy/pasted the given example, changed variables, and changed the variable the sheet worker sends the processed stats to.  I also tried changing some attributes in my INPUTs to see if it mattered.  I just get placeholders in the input boxes-- no calculated values.  Any thoughts why this isn't working? SHEET WORKER section: // TEST a LOOPED WORKER // 1. on the const stats array, use only small letters (no caps) since these go into the "on/change" portion, which cannot take caps. // const stats = ['str','dex','agi','con','edu','per']; stats.forEach(function (stat) {     on("change:" + stat + " sheet:opened", function () {         getAttrs([stat], function (values) {             const stat_score = parseInt(values[stat], 10)||0;              const stat_modifier = Math.floor(stat_score/2) -5;              setAttrs({                 [stat + '_test']: stat_modifier              });         });     }); }); HTML section: <tr>                     <td class="attr-label" ><strong>str/dex _test</strong></td>                     <td><input style="width:95%" class="attrmod-input" type="text" placeholder="txt" name="attr_str_test"/></td>                     <!--- The above code WILL display the correct text, by making the NAME value the same as the NAME value of the original input  --->                     <td><input style="width:95%" class="attrmod-input" type="text" placeholder="txt" name="attr_dex_test" readonly/></td>                     <!--- With READONLY, the above code WILL display the correct text, by making the NAME value the same as the NAME value of the original input  --->                     <!--- BUT, how do you put the value of one INPUT's NAME attribute as the value of another INPUT's NAME attribute?? --->                     <td> </td>                     <td class="attr-label" ><strong>agi/con _test</strong></td>                     <td><input style="width:95%" class="attrmod-input" type="number" placeholder="num" name="attr_agi_test"/></td>                     <!--- The above code WILL display the correct number, by making the NAME value the same as the NAME value of the original input  --->                     <td><input style="width:95%" class="attrmod-input" type="number" placeholder="num" name="attr_con_test"/></td>                     <!--- With DISABLED, the above code will NOT display the correct number, but will show the placeholder  --->                     <td> </td>                     <td class="attr-label"><strong>edu/per _test</strong></td>                     <td><input style="width:95%" class="attrmod-input" type="number" placeholder="num" name="attr_edu_test" value="attr_edu_test"/></td>                     <td><input style="width:95%" class="attrmod-input" type="number" placeholder="num" name="attr_per_test" value="attr_per_test" readonly/></td> </tr>
1610222853
Andreas J.
Forum Champion
Sheet Author
Translator
Have you tried adding console.log() to a couple of places to see what might be happening? Have you tried removing the "on: sheet open" condition? the sheetworker trigger every time you open a sheet, which seems redundant unless you edit sheet stats without opening sheets, like with ChatSetAttr. Are your other sheetworkers editing same stats as the UniversalSheetWorker?
Thanks for replying.  I'll start working on it with your suggestions.
1610385484
GiGs
Pro
Sheet Author
API Scripter
There's nothing wrong with the sheet worker posted here - there's no reason it should break your other sheet workers. If that is happening, the problem is somewhere else. Can you post your sheet to pastebin.com or gist.com, so we can look at the script block. I suspect there's an error in that block that is making it look like the error is in this worker. Also can you post the code for your stat score inputs - you've only posted the ones ending in _test above, and it might help to look at the the str, dex, etc., inputs and their modifier inputs.