The first of your examples looks perfectly fine. The second is not. This section in the second one has the mistake: setAttrs({ felbns: values.felcalc }); The values object is created by getAttrs, and contains the attributes you've declared. So when you do this getAttrs(["fellowship","unfel"], function(values) { this is a command to tell roll20: "look at the character sheet, find the attributes named fellowship and unfel , and put them in a variable called values ." So when this sheet worker runs, it has access to a values object, which is a variable that looks like this: values = {
fellowship: 3,
unfel: 2
} (numbers made up for the example; this is an object - a type of variable which can hold multiple other variables within it. Here it contains two - fellowship and unfel - their names and their values.) Then when you do this const fel = values.fellowship; (I stripped out the part of the code, to focus on this part) you are accessing that values object, and getting the fellowship value from it. The values object contains only the attributes defined in the getAttrs line. So getting back to this setAttrs({ felbns: values.felcalc }); This is looking for an attribute named felcalc in the values object, which doesnt exist. And so this will throw an error. Your first sheet worker code though is perfectly fine. That should work. That suggests the error is somewhere else in the sheet. My first question is the same as Aaron's- is the script block set up correctly? Secondly, I'd look at the html for these attributes. Are the attribute names defined properly. Its common for first time coders to forget the "attr_" part of attribute names (I still do it from time to time). If there are autocalc values in either of those attributes, that'll cause issues too (because of the way the code is written, it should still run, but the values of the attribute will always be zero). I'd follow Aaron's suggestion and put a console.log statement or two in your code, like so: console.log("%c===== The script block is working","color:red");
on("sheet:opened change:fellowship change:unfel", function() { console.log("%c===== The change event fired correctly","color:red");
getAttrs(["fellowship","unfel"], function(values) {
console.log("%c===== The getAttrs command worked, values equals:","color:red");
console.log(values);
const fel = parseInt(values.fellowship,10)||0;
console.log("%c===== fel = " + fel,"color:red");
const unfel = parseInt(values.unfel,10)||0;
console.log("%c===== unfel = " + unfel,"color:red");
const felcalc = Math.floor(fel/2) + unfel;
console.log("%c===== felcalc = " + felcalc,"color:red");
setAttrs({
felbns: felcalc
});
});
}); Then open the browser console when you try to change anything, and you should be able to spot whether anything happens. The comnsole statements will be in red text, with "======" at the start, so should be easy to find. When you first open the character sheet, before doing anything, look for this in the console : "====== The script block is working" If its not there, there's an issue with your script block and none of your code will work. Assuming thats fine, you should get the console statements when you change things, and you can check at which point it breaks. If any console statement doesnt appear, then thats where it breaks. If they do appear, but have the wrong values, you can check the html to see why they have the wrong values.