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

[Custom Sheet] Auto fill in Skills by adding up Attributes using Worker Scripts

1489574340

Edited 1489575882
Hello there! I'm creating my first custom character sheet and I'm hitting a snag with Worker Scripts. I've poured hours on the Wiki and Forums, and while I've tried to emulate some of the answers there, I just can't figure out why a simple sum is not working here... Please bear in mind that I have no prior knowledge in this what so ever, I'm learning on the fly :) I've defined my Strength and Intellect attributes and my Combat skill like so : <td>Force</td> <td><input type=number width=5 style='width: 5em;' name="attr_for" value="0"/></td> <td>Intellect</td> <td><input type=number width=5 style='width: 5em;' name="attr_int" value="0"/></td> <td>Combat</td> <td><input type=number width=5 style='width: 5em;' name="attr_com" readonly/></td> Later on, when using my Worker Script to define and update my Combat skill, I wrote this : on("change:for", "change:int", function() {   getAttrs(["for", "int"], function(values) {   setAttrs({                   com: Math.floor(parseInt(values.for) + parseInt(values.int))      });    }); }); I really don't see where I'm not doing it right, the field on the sheet is blank and nothing happens when I update the atrribute fields... and I have four attributes total and ten linked skills that are acting up this way. Any help and insight would be greatly appreciated! Edit : formatting
1489580904
Loki
Sheet Author
Hello Slyfox! The syntax for triggering sheet workers is on("Event(s)", callback_Function); So instead of using on("change:for", "change:int", function() { ... }); you should use on("change:for change:int", function() { ... }); You'd also want to add a default value to your attr_com, as your sheet workers will only trigger when a change is made, leaving the value empty for new characters. (Possibly messing up other calculations) <input type=number width=5 style='width: 5em;' name="attr_com" value="0" readonly/> You're welcome!
1489593748
Lithl
Pro
Sheet Author
API Scripter
Loki said: You'd also want to add a default value to your attr_com, as your sheet workers will only trigger when a change is made, leaving the value empty for new characters. (Possibly messing up other calculations) <input type=number width=5 style='width: 5em;' name="attr_com" value="0" readonly/> Alternatively, add sheet:opened to the event string.
1489737847

Edited 1489737862
Thank you so both so much! That did it wonderfully. Also I had an extra ")" that made the script go AWOL.