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 help needed

OK. I am trying to use sheetworker to overcome the issue I am having with auto calc values not being useable by tokens for their bar values etc. I am trying to have the sheetworker set the value for Armor Class (A.C. is the attribute). It is based on a variety of attributes and can be further modified by maneuvers that the player can toggle on and off through macros or checkboxes on the character sheet.  Currently it isn't working. This is what I have: <script type="text/worker"> on("change:armorac change:shieldac change:modac change:magicac change:miscac change:shieldready changes:retreat change:parry change:evade change:dodgeaction change:offensivefocus change:charge change:marauder change:giants change:miscac2 changed:dexteritymod change:overburdened change:def sheet:opened", function(values) {            getAttrs(["ArmorAC","ShieldAC",”ModAC”,”MagicAC”,”MiscAC”,”ShieldReady”,”Retreat”,”Parry”,”Evade”,”DodgeAction”,”OffensiveFocus”,”Charge”,”Marauder”,”Giants”,”MiscAC2”,”DexterityMod”,”OverBurdened”,”Def”], function(values) {         let armorac = parseInt(values.ArmorAC)||0;         let shieldac = parseInt(values.ShieldAC)||0;         let modac = parseInt(values.ModAC)||0;         let magicac = parseInt(values.MagicAC)||0;         let miscac = parseInt(values.MiscAC)||0;         let shieldready = parseInt(values.ShieldReady)||0;         let retreat = parseInt(values.Retreat)||0;         let parry = parseInt(values.Parry)||0;         let evade = parseInt(values.Evade)||0;         let dodgeaction = parseInt(values.DidgeAction)||0;         let offensivefocus = parseInt(values.OffensiveFocus)||0;         let charge = parseInt(values.Charge)||0;         let marauder = parseInt(values.Marauder)||0;         let giants = parseInt(values.Giants)||0;         let miscac2 = parseInt(values.MiscAC2)||0;         let dexteritymod = parseInt(values.DexterityMod)||0;         let overburdened = parseInt(values.Overburdened)||0;   let def = parseInt(values.Def)||0; let ac = 10 + ArmorAC + (ShieldAC * ShieldReady) + ModAC + MagicAC + MiscAC -retreat + Parry + Evade + DodgeAction – (OffensiveFocus * 2) - (Charge * 2) + Marauder + Giants + MiscAC2 - (DexterityMod * OverBurdened);  setAttrs({                                  "A.C.": ac }); }); });
1614826477
GiGs
Pro
Sheet Author
API Scripter
You have smart quotes in your getAttrs, like this:  ” ModAC ” Notice the quotes are ” instead of ". Word processors often change the quotes as you type them, to make them look prettier. Unfortunately programming languages usually cannot recognise those quotes and so they break the code. So change the getAttrs line to this: getAttrs(["ArmorAC","ShieldAC","ModAC","MagicAC","MiscAC","ShieldReady","Retreat","Parry","Evade",     "DodgeAction","OffensiveFocus","Charge","Marauder","Giants","MiscAC2","DexterityMod","OverBurdened","Def"], function(values) { Thats the first problem. The second issue is variable names are case-sensitive. For example you have at the start: let   armorac  =  parseInt ( values . ArmorAC )|| 0 ; But in your calculation later, you have let   ac  =  10  +  ArmorAC  + notice ArmorAC should be exactly the same as the variable name, which is armorac. The final issue I spot is you have the wrong sort of dash in the calculattion: you have this – ( OffensiveFocus  *  2 ) - but the first dash there is not a subtract sign. so you need to fix that to: - ( OffensiveFocus  *  2 ) - Its likely some of these issues were caused by writing your code in a 'smart' editor like a word processor, then pasting them into the code window. For programming, you should never write your code in that kind of editor - use basic notepad, or a programming editor like VS Code, Sublim Text, Atom, or Notepad++. The final point might not be an error. setAttrs ({                                   "A.C." :   ac }); This suggests you have created an attribute with the name A.C. - that's not a good idea. I would change the name to simply AC. Avoid punctuation or spaces in attribute names. I believe roll20 will accept them, but they are a source of frequent errors in macros and in sheet workers.
1614826668
GiGs
Pro
Sheet Author
API Scripter
One final note. Your very first line ends change:overburdened change:def sheet:opened" ,  function ( values ) { That should be change:overburdened change:def sheet:opened" ,  function () {        You dont need to include any text there, unless you are using the eventInfo object (you aren't here), and you would call it something other than values since you are using that later.
Thank you.  Final question (for now). Do I need to write the attribute that is being modified in a certain way in the html code, or will standard work?
1614828603

Edited 1614828666
GiGs
Pro
Sheet Author
API Scripter
It just needs to match the name after the attr_ part. Case in this case doesnt matter. So if your attribute is  created with <input type="number" name="attr_AC" value="0"> then in the sheet worker, you can use any of setAttrs({      "AC": ac }); setAttrs({      "ac": ac }); setAttrs({      "Ac": ac }); setAttrs({      "aC": ac }); or even setAttrs({      AC: ac }); You dont need quotes there. You can even do setAttrs({      ac }); When the variable name is the same as the attribute it is being assigned to (and remember AC is the same as ac , because case doesn't matter), you can list it alone.  Note: if the attribute name is actually "A.C." you do need quotes and you cant use that last method - because punctuation makes things trickier.
Appreciate the help. But I am still doing something wrong.
1614830559
GiGs
Pro
Sheet Author
API Scripter
Post the current version of the sheet worker.
<script type="text/worker"> on("change:armorac change:shieldac change:modac change:magicac change:miscac change:shieldready change:retreat change:parry change:evade change:dodgeaction change:offensivefocus change:charge change:marauder change:giants change:miscac2 change:dexteritymod change:overburdened change:def sheet:opened", function() {            getAttrs(["ArmorAC","ShieldAC","ModAC","MagicAC","MiscAC","ShieldReady","Retreat","Parry","Evade","DodgeAction","OffensiveFocus","Charge","Marauder","Giants","MiscAC2","DexterityMod","OverBurdened","Def"], function(values) {         let armorac = parseInt(values.ArmorAC)||0;         let shieldac = parseInt(values.ShieldAC)||0;         let modac = parseInt(values.ModAC)||0;         let magicac = parseInt(values.MagicAC)||0;         let miscac = parseInt(values.MiscAC)||0;         let shieldready = parseInt(values.ShieldReady)||0;         let retreat = parseInt(values.Retreat)||0;         let parry = parseInt(values.Parry)||0;         let evade = parseInt(values.Evade)||0;         let dodgeaction = parseInt(values.DodgeAction)||0;         let offensivefocus = parseInt(values.OffensiveFocus)||0;         let charge = parseInt(values.Charge)||0;         let marauder = parseInt(values.Marauder)||0;         let giants = parseInt(values.Giants)||0;         let miscac2 = parseInt(values.MiscAC2)||0;         let dexteritymod = parseInt(values.DexterityMod)||0;         let overburdened = parseInt(values.OverBurdened)||0;   let def = parseInt(values.Def)||0; let ac = 10 + armorac + (shieldac*shieldready) + modac + magicac + miscac - retreat + parry + evade + dodgeaction - (offensivefocus*2) - (charge*2) + marauder + giants + miscac2 - (dexteritymod*overburdened);  setAttrs({                                 ac }); }); });
1614877154
GiGs
Pro
Sheet Author
API Scripter
That looks like it should work, so its time to look outside the sheet worker. Do you have an  </script> line after all your sheet workers? Check the html for the attributes - are any of them autocalc or disabled? sheet workers cannot work with disabled attributes. If you click F12 in the campaign, you'll get access to the browser dev console. Then when you change one of the attributes, an error should appear in the console. If so, you can post that here. Minor note (unrelated to your error), you get the value of a Def attribute, but you dont use that in ac calculation.
d'oh
1614896651
GiGs
Pro
Sheet Author
API Scripter
Does that mean you've found the source of the issue?
I managed to get it working. For now.