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

[Sheet worker] PF simple @{HP|max} issue

1456825554
vÍnce
Pro
Sheet Author
Another member brought up an issue with the PF simple sheet that I was hoping to rectify. Problem: Total HP uses @{ HP|max } and current HP is @{HPCurrent} You cannot properly link HP to tokens using these two attributes. @{ HP|max } actually uses name="HP|max" instead of name="HP_max". This causes a few problems; It cannot be used as the max value for anything, specifically @{HP} nor @{HPCurrent}. Although you an plainly see "HP|max" and it's value on the Attributes and Abilities tab of the journal, you cannot pull the attribute's value. I've tried @{selected|HP|max} and @{ Enter Characters Name |HP|max} and you just get a "No Attribute was found" error. I believe Roll20 gets confused since this attribute includes " | " in it's name. Solution 1:   My proposal is to change the attribute used for Total HP from @{HP|max} to @{HPCurrent_max}. That way sheets could keep their current HP and be able to properly link their HP to a token's bar. I included a note at the top of the sheet asking that existing sheets manually enter their Total HP into the new @{HPCurrent_max} field/attribute using the Attributes and Abilities tab as a reference. Solution 2:   Phil B.(Dev) wisely pointed out that I should use sheet workers to handle the transition automatically. With my very limited js skills I've been able to "cobble/steal" Chris's sheet version/detection code(Thank you Chris) which works splendidly, but due to my limited knowledge of js and/or this problematic attribute @{HP|max} I'm not sure how to proceed. I'm stuck at just trying to get a log detecting @{HP|max}. Code below fails(no errors, but the js stops) BTW, if I use HPCurrent in place of HP|max, everything works.  So I think it has to be a conflict with the name...  any help?  TIA <script type="text/worker"> var Sheet = Sheet || (function(){ var version= 0.1, Debug = false, updateHP = function() { getAttrs([" HP|max "], function(values) { var HP|max =(parseInt(values. HP|max )); console.log(" HP|max =" + HP|max ); }); }, /* recalculateSheet */ recalculateSheet = function(oldversion) { if (oldversion < 0.1) { updateHP(); } }, /* checkForUpdate looks at current version of page in Sheet_Version and compares to code Sheet.version calls recalulateSheet if versions don't match or if recalculate button was pressed. */ checkForUpdate = function(){ getAttrs(["Sheet_Version","Sheet_forcesync","recalc1"],function(v){ var setter={},currVer=0,setAny=0,recalc=false; currVer=parseFloat(v["Sheet_Version"],10)||0; console.log("Current sheet data version:"+currVer+", Sheet code version:" + version ); if ( currVer!== version ) { recalc=true; setter["Sheet_Version"]= version; setAny=1; } if (v["recalc1"] && v["recalc1"]!="0" ) { currVer=-1; recalc=true; setter["recalc1"]=0; setAny=1; } if (v["Sheet_forcesync"] && v["Sheet_forcesync"]!="0" ) { currVer=-1; recalc=true; setter["Sheet_forcesync"]=0; setAny=1; } if (setAny) { setAttrs( setter); } if (recalc) { recalculateSheet(currVer); } }); }; return { version:version, checkForUpdate:checkForUpdate, updateHP:updateHP }; }()); //sheet on("sheet:opened",function(){Sheet.checkForUpdate();}); on("change:recalc1",function(){Sheet.checkForUpdate();}); </script>
1456844165
Diana P
Pro
Sheet Author
I can't help with the javascript, but a possible different solution to that problem is to just turn the original field into a hidden field and set the new field's value to be equal to it.  That's what I did when I updated the 3.5 sheet AC calculation area so folk didn't have their AC's suddenly change or disappear on them mid-campaign.  It probably won't work well if the HP is calculated, but basically what I did was: <input type="hidden" name="attr_armorclassmiscmod" title="armorclassmiscmod" value="0" /> <!--the original ACMiscmod; the value=0 is to prevent errors if it never existed before this update--> <input type="text" name="attr_miscac1bonus" title="miscac1bonus" value="@{armorclassmiscmod}" /> <!-- new field -->
1456859043
vÍnce
Pro
Sheet Author
Thanks Diana. I believe I actually tried that as my initial solution hoping for a quick fix. ;-P Couple of problems however, This method of subbing values only seems to work if the new field is disabled, otherwise the unresolved attribute name shows up as the new value.  Unfortunately, the Total HP on the sheet is a user editable field/attribute.  This can probably be worked around by adding a new editable field if needed, however... The bigger issue is that roll20 just refuses to work with the attribute  @{HP|max}  Even if I change Total HP to a disabled field, nothing shows up for the new value when subbing @{HP|max} as the value. Ugh.  I seem to be stuck trying to fix a broken attribute that just will not cooperate.
1456860760
Diana P
Pro
Sheet Author
*nod*  it probably worked for me because my final calculation was disabled so it didn't matter that the interim value just showed something odd. one last thought (to go with the sheet workers method) Maybe you can get around the | in your name the same way I get around having dashes in the names of some of my attributes: using something like parseInt(values["cat-armor-heavy-ranks"]) instead of parseInt(values.catprog0) maybe  var HP|max=(parseInt(values.HP|max));  would work as  var HPmax=(parseInt(values["HP|max"]);  ? (I think the first name is just a variable?) then I think the console line could be:  console.log("HP|max=" + HPmax); But I could be wrong.  I'm not at all good with javascript.
1456861944
vÍnce
Pro
Sheet Author
That was a great idea... sadly that also fails.   I think I might need to throw this at the Bugs forum although it's technically not a bug.  Other than the system might think @{HP|max} is a character named "HP" with an attribute named "Max" (popular at the Oscars this year...).
1456864887
Diana P
Pro
Sheet Author
*nod*  might not be a bad idea to toss this in the bugs forum. Though I hope you saw that I missed a closing parenthesis when trying my idea above:  var HPmax=(parseInt(values["HP|max"] ) );    Sorry, I can't think of any other ideas.  :\   Good luck.
1456865831
vÍnce
Pro
Sheet Author
LOL Of  Diana P said: *nod*  might not be a bad idea to toss this in the bugs forum. Though I hope you saw that I missed a closing parenthesis when trying my idea above:  var HPmax=(parseInt(values["HP|max"] ) );    Sorry, I can't think of any other ideas.  :\   Good luck. Of course I didn't  lol THAT does function!  Thanks Diana.  Now I just need to work out the swap.
1456866394
Diana P
Pro
Sheet Author
\o/  Yay!  I got the answer right!  On a programming question!  Without asking my husband/programmer-in-residence!  I might be actually starting to get the hang of some of the syntax even if I can't do more than move things around and brute force them. :) the rest should be easy?  something like setAttrs({ newattribute: HPmax });  right?  Though where to put that line..... :) You're welcome and Good luck on the rest of it!