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>