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 .
×
Advertisement Create a free account

Sheetworker Autocalc v0.1.0

1488576985
Brian
Sheet Author
API Scripter
As a character sheet author, have you struggled over the tradeoffs between autocalc fields and writing worker scripts? There is a solution! Sheetworker Autocalc  will let you resolve the autocalc fields to a value, which you can use in your sheet worker as you please. Simply add the code to your sheet worker, and then call resolveAutocalc . Here's the function in action: <input type="number" name="attr_a" value="2"> <input type="number" name="attr_b" value="3"> <input type="number" name="attr_c" value="(@{a}+1)" disabled> <input type="number" name="attr_d" value="@{c}+@{b}" disabled> <input type="number" name="attr_e" readonly> <input type="number" name="attr_f" readonly> <script type="text/worker"> on('sheet:opened change:a change:b', function() { // specify the attribute to resolve: resolveAutocalc('d', function(values) { // you get its value, and the value of all attributes it references: // values = { a: 2, b: 3, c: 3, d: 6 } setAttrs({ e: Math.pow(values.d, 2); }); }); // it also works with an array: resolveAutocalc(['a', 'b'], function(values) { // it works with non-autocalc attributes, too: // values = { a: 2, b: 3 } }); // you can easily test what version you've got: console.log(resolveAutocalc.VERSION); // 0.1.0 }); // sheetworker-autocalc.js goes here </script> Sheetworker Autocalc supports the floor, ceil, round, and abs functions as well as the +, -, *, /, %, and ** operators,  just like autocalc fields. Version 0.1.0 has not been tested with repeating sections. sheetworker-autocalc.min.js is available in the linked repository for a minified version of the code, if you prefer to scroll past just 25 lines instead of 143!
1488634111
Alicia
Sheet Author
Hmm nice. This might be a piece I was missing to transfer a lot of my calculation fields to sheet workers