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

Q: Can you use Auto-Calculated field values in Worker Scripts

So, I've been trying to get a new feature on a character sheet that is based on the values of a calculated field. But every time I try to get the field in question it returns the string such as "(@{strength_base} + @{strength_mod})". So, my question is: can I get the already calculated value somehow? And yes, I get that I could get the base values that are used in a calculated field... but that will be VERY cumbersome, as many of the values I need have several layers of calculations before you get to the "base". (ex: Dodge is based on Speed +3+Dodge_Mod, Speed is based on Dexterity , Health , Speed_points, and Speed_mod, Dexterity and Health are both based on their own points and mods...) .
1486912125
Pat S.
Forum Champion
Sheet Author
What is the actual macro?
1486923350
Lithl
Pro
Sheet Author
API Scripter
Sheet workers don't have a method to get the final result of an autocalc field, although as you mentioned you could conceivably write your own engine to calculate it.
1486924143
Finderski
Pro
Sheet Author
Compendium Curator
Probably not what you're looking for, but you could also move the calculation for the calculated fields into a sheet worker, the. You could get the value for the calculation without having to recalculate....
Well one of the fields that I need is basic_lift which is "round(((@{lift_st}) * (@{lift_st}))/5)". Of course "lift_st" is also a calculated field of "@{lift_st_base} + @{lift_st_mod}", and lift_st_base is "@{strength} + floor(abs(@{lift_st_points}) / 3) * (@{lift_st_points}+1)/abs(@{lift_st_points}+1)", and strength is "(@{strength_base} + @{strength_mod})" and strength_base is "(10 + floor(abs(@{strength_points}) / 10) * (@{strength_points}+1)/abs(@{strength_points}+1))" I need to use this in a script where encumbrance level is based on the total_weight they carry as a multiple of the basic_lift. The code is as follows: var encumbranceLevel = Math.floor(val.total_weight / basicLift ); if (encumbranceLevel > 0 && (val.total_weight % basicLift ) === 0) { encumbranceLevel--; } if (encumbranceLevel >= 10) { encumbranceLevel = 5; } else if (encumbranceLevel >= 6) { encumbranceLevel = 4; } else if (encumbranceLevel >= 3) { encumbranceLevel = 3; } setAttrs({ encumbrance_level: encumbranceLevel }); And this is just ONE example of where I need to do something. So I COULD get strength_points, strength_mod, lift_st_points, lift_st_mod, and recalculate everything... but at that point I might as well dump all the auto-calculated fields and replace them script built fields.
Yeah, I've actually made a copy of the sheet that has most of the fields built by the sheet workers.. but I'm worried about pushing it up and breaking all the users that have the sheet working now. I've made a script to check if the fields are set on sheet open... but the callbacks don't seem to be working right and the diriviative values aren't getting the data they need to be set (even when called from the callback on setAttr). <sigh> I guess I'll just have to keep fiddling with it.
1487491671

Edited 1487687316
chris b.
Pro
Sheet Author
API Scripter
if you look at our code we bastardized the Extended Expressions API script so the sheetworkers could&nbsp;search and replace the attributes, then figure out the equation. basically it starts with&nbsp;evaluateAndSetNumber on the attribute that has your macro in it, and you give it that and the field you want to write the result to. <a href="https://github.com/plutosdad/SheetWorkerParsing/" rel="nofollow">https://github.com/plutosdad/SheetWorkerParsing/</a> note this is slow, we only use it to allow users to add their own macros. You wouldn't want to use it to evaluate things that never change. But yea, once you start you end up having to replace just about everything, because those fields depend on other fields, and those depend on others, and so on and so on, elephants all the way down.
1488586753
Lithl
Pro
Sheet Author
API Scripter
Here's a solution I've devised to calculate the values of an autocalc field (or multiple) in a sheet worker:&nbsp; Sheetworker Autocalc