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

Help with a Sheetworker

Good Day, I am rather new to sheetworkers, and not at all experienced in javascript, having only used one sheetworker in my custom character sheet for the first time this week. While I have managed to get one working to calculate repeating inventory weight (through mostly copy/paste from the example versions), one that I am trying to make right now does not seem to want to work. It doesn't seem that complicated to me, so I am not sure what I am doing wrong. Basically, my character sheet has inputs for inherent armor, two suits of armor, and three shields, with checkboxes to determine if any of them are actually "equipped" at that moment and should be counted. I am currently achieving this with autocalc fields, but that is inefficient because it means the entire formula (of which this is only the first part) is included in every single roll. Once I have this basic part working, I can then expand this sheetworker with the rest of the formula. I have already made sure that the base_phys_arm attribute (which should be set by this worker) is not disabled. Any advice would be appreciated. /* Physical Armor Sheetworker */ on("change:inh_arm_phys change:armorvalue_phys change:armorvalue_phys_2 change:shieldarmor_phys change:shieldarmor_phys_2 change:shieldarmor_phys_3 change:armequip change:armequip_2 change:shieldequipped change:shieldequipped_2 change:shieldequipped_3", function() {               getAttrs(["INH_ARM_PHYS","ARMORVALUE_PHYS","ARMORVALUE_PHYS_2","SHIELDARMOR_PHYS","SHIELDARMOR_PHYS_2","SHIELDARMOR_PHYS_3","ARMEQUIP","ARMEQUIP_2","SHIELDEQUIPPED","SHIELDEQUIPPED_2","SHIELDEQUIPPED_3"], function(values) {                 let inh_arm_phys = parseInt(values.INH_ARM_PHYS)||0;                 let armorvalue_phys = parseInt(values.ARMORVALUE_PHYS)||0;                 let armorvalue_phys_2 = parseInt(values.ARMORVALUE_PHYS_2)||0;                 let shieldarmor_phys = parseInt(values.SHIELDARMOR_PHYS)||0;                 let shieldarmor_phys_2 = parseInt(values.SHIELDARMOR_PHYS_2)||0;                 let shieldarmor_phys_3 = parseInt(values.SHIELDARMOR_PHYS_3)||0;                 let armequip = parseInt(values.ARMEQUIP)||0;                 let armequip_2 = parseInt(values.ARMEQUIP_2)||0;                 let shieldequipped = parseInt(values.SHIELDEQUIPPED)||0;                 let shieldequipped_2 = parseInt(values.SHIELDEQUIPPED_2)||0;                 let shieldequipped_3 = parseInt(values.SHIELDEQUIPPED_3)||0;                 let physarmor = (@{inh_arm_phys} + (@{armorvalue_phys} * @{armequip}) + (@{armorvalue_phys_2} * @{armequip_2}) + (@{shieldarmor_phys} * @{shieldequipped}) + (@{shieldarmor_phys_2} * @{shieldequipped_2}) + (@{shieldarmor_phys_3} * @{shieldequipped_3}));                 setAttrs({                                                 base_phys_arm: physarmor                 });             });         });/* END Physical Armor Sheetworker */
1601581056
GiGs
Pro
Sheet Author
API Scripter
This line wont work in sheet workers: let physarmor = (@{inh_arm_phys} + (@{armorvalue_phys} * @{armequip}) + (@{armorvalue_phys_2} * @{armequip_2}) + (@{shieldarmor_phys} * @{shieldequipped}) + (@{shieldarmor_phys_2} * @{shieldequipped_2}) + (@{shieldarmor_phys_3} * @{shieldequipped_3})); Sheet workers have no knowledge of anything outside the worker - the character sheet doesnt exist as far as they are concerned. So you cant use @{} syntax to grab attribute values. thats what the getAttrs function is for. Are these values in a repeating section? If so you aren't using the proper attribute names. If these aren't in a repeating section, you are SO close. Just remove the @{} from each variable name on the let physarmor line, like so let physarmor = inh_arm_phys + armorvalue_phys * armequip + armorvalue_phys_2armequip_2 + shieldarmor_phys * shieldequipped + shieldarmor_phys_2 * shieldequipped_2 + shieldarmor_phys_3 * shieldequipped_3; Javascript (which is what sheet workers use) follows the rules of arithemtic, so you don't need to use ( ) in the above expression. Multiples are always done before pluses. Note that for this to work, your checkboxes need to have value="1"  in the html.
Thank you very much. Removing the attribute calls fixed it, nice and easy.  I figured it might be something silly like that. I'm so used to making autocalc fields and macros that I didn't even bat an eye at the attribute calls on it. 
1601582503
GiGs
Pro
Sheet Author
API Scripter
Great! and I've done that kind of thing too :)