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

Sheet Workers and Default Values

1515583375

Edited 1515584686
Hello! I'm running into an issue with a character sheet I'm designing and a sheet worker to calculate a stat based on its base times a multiplier. However, it doesn't seem like the default values I placed in the attribute fields are being used when I update the base value, so even though the character sheet may say, for example, 3 × 1, the sheet worker doesn't update the field to display the expected value (3). HTML: <span class="sheet-charstats">     <input class="sheet-base" name="attr_strength" type="number" min="0" step="1" value="0" /> </span> <span class="sheet-charformula">     <input class="sheet-base" name="attr_strength_base" type="number" min="0" step="1" value="0" />     ×<input class="sheet-base" name="attr_strength_multi" type="number" min="0" step="0.1" value="1" /> </span> Worker: on("change:strength_base, change:strength_multi", function(eventInfo) {     getAttrs(["strength_base", "strength_multi"], function(values) {         var base = parseInt(values["strength_base"]);         var multi = parseFloat(values["strength_multi"]);         setAttrs({             strength: Math.ceil(base * multi)         });     }); }); I'm not sure what I'm doing wrong. Any assistance would be greatly appreciated. Thank you for your time! Edit: Tried to search the forum for search terms like "Sheet Worker Default Values" but didn't see any solution in code, so I wasn't sure where to turn. Apologies if this has been answered multiple times before. Edit 2: Also forgot to note I did try the below as well to no avail. Trying to debug with console.log also seemed to get nowhere when checking these values. I received no output in the browser's JS console. var base = parseInt(values["strength_base"]) || 0; var multi = parseFloat(values["strength_multi"]) || 1;
1515585677
Jakob
Sheet Author
API Scripter
I don't know if there are other issues, but at least your event string is wrong. It should be "change:strength_base change:strength_multi" without a comma.
1515586141
GiGs
Pro
Sheet Author
API Scripter
I created a new campaign and added the code below as a custom character sheet (just your code above combined), and it worked perfectly. When a script stops working, there are two main possibilities: a) there's a problem in that script. b) there's a problem in another  script, serious enough to cause all sheet workers in the sheet to stop working. I think you have an issue somewhere else in the character sheet. Have you any other sheet workers? For the record, here's the code I used to test: <span class="sheet-charstats">     <input class="sheet-base" name="attr_strength" type="number" min="0" step="1" value="0" /> </span> <span class="sheet-charformula">     <input class="sheet-base" name="attr_strength_base" type="number" min="0" step="1" value="0" />     ×<input class="sheet-base" name="attr_strength_multi" type="number" min="0" step="0.1" value="1" /> </span> <!-- SHEET WORKERS --> <script type="text/worker"> on("change:strength_base, change:strength_multi", function(eventInfo) {     getAttrs(["strength_base", "strength_multi"], function(values) {         var base = parseInt(values["strength_base"]);         var multi = parseFloat(values["strength_multi"]);         setAttrs({             strength: Math.ceil(base * multi)         });     }); }); </script>
Thanks for the help, everyone! As it turns out the errant commas in the 'on(...)' lines seemed to be the culprit. I just went and removed them and the sheet is now working 100% properly.
1515599118
GiGs
Pro
Sheet Author
API Scripter
aha, I missed that. Well done.