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

Sheetworker confusion

1548086343

Edited 1548086442
Kraynic
Pro
Sheet Author
I have been altering a sheet for my own use for some time now, and I finally got around to thinking about sheet workers.  I don't have a lot of things I would like to automate, and most of them are really simple mathematically.  However, I just can't seem to wrap my head around the sheetworker examples on the wiki. As an example, I would like to take the Physical Strength stat, multiply that stat by 20, and have the result entered as Lift.  I have been fiddling with the universal sheetworker code from the wiki.  The attribute for Physical Strength is "ps", and the attribute for Lift is "lift". on("change:ps sheet:opened", function () { getAttrs(['ps'], function (values) { const ps = parseInt(values['ps'], 10)||0; // this extracts the stat, and assumes a stat score of 0 the stat is not recognised as a number. const modifier = Math.(ps*20); setAttrs({ lift: modifier }); }); }); But that doesn't seem to be working for me.  I expect I am missing something really simple, but have no idea what it may be.  Help?
1548087611
Andreas J.
Forum Champion
Sheet Author
Translator
Okay I'm not good at this, but I can point out that there exist now two more pages that details how sheetworkers can work , apart form the main page. I've also linked these newer pages made by GiGs at the bottom of the main sheetworker page.
1548089036
Kraynic
Pro
Sheet Author
Yeah, I have looked those over.  From one of those examples, I tried: on("change:ps sheet:opened", function () { getAttrs(['ps'], function (values) { setAttrs({ lift: math.(values.ps*20) }); }); }); It doesn't seem to work either.  I expect I am just not understanding something that is really simple, and I will feel foolish once I do.
1548103309

Edited 1548111942
GiGs
Pro
Sheet Author
API Scripter
Your math statement isn't correct syntax. You dont need to use Math. for simple arithmetic, it's only used for specific functions like Math.floor. on("change:ps sheet:opened", function () { getAttrs(['ps'], function (values) { const ps = parseInt(values['ps'], 10)||0; const modifier = ps*20; setAttrs({ lift: modifier }); }); }); If your input is of type number, you can make this a lot simpler. on("change:ps sheet:opened", function () { getAttrs(['ps'], function (values) { setAttrs({ lift: values.ps * 20 }); }); }); I always include the const statements in my examples, because that structure is easier to debug when you have a problem. If the second version doesnt work, try the first. The second version will fail if the input/attribute 'ps' ever has a non-numerical value (possibly including being empty).
1548123681
Kraynic
Pro
Sheet Author
Thanks!  I did end up using the first version, and had the Math in there for a couple things I decided to do later.  I have now have 7 little boxes happily filling themselves in based on other manually filled boxes.