I asked about the roll just in case I needed to see it to understand how you are using the stat, but t's okay, I dont think I need it. If you give the exact stat names and formula used to calculate them, I could give the sheet worker you need. But here's in imaginary proof of concept: Imagine you have three stats, str, dex, and int. Defence is the average of those three stats, with a maximum value of 75. Here's one way to build the sheet worker you'd use to calculate that: on("change:str change:dex change:int sheet:opened", function() { getAttrs(["str", "dex", "int"], function(values) { const str = +values.str||0; const dex = +values.dex||0; const int = +values.int||0;
let score = Math.round((str + dex + int)/3); score = Math.min(score,75);
setAttrs({ defence: score }); }); }); The first line sets up a watcher. Whenever any of the stats change, the sheet work runs. Sheet workers have no direct access to the character sheet. They don't know what stats exist. So the second line uses the getAttrs function to grab the attributes named, and store them in a variable called values. Now the sheet worker has access to them. The three const lines extract the attribute scores from the values object, and associate them with variables names str, dex, and int. The three steps described above are the core steps you will do over and over when making sheet workers. First set up a watcher to monitor the sheet, then grab the values you need to manipulate. Now you can get around to do the actual operation the sheet worker is for. In this case, I create a variable named score, and calculate its value from those attributes. Now in the final step that every sheet worker will have (setAttrs), we save that calculated score to the character sheet. This assumes you have an attribute named defence. You should be able to use this to create your own sheet workers- just change the stat references. One thing to be careful of: Make sure all your attributes are named in lower case, and avoid using a dash within their names. For instance, don't use defence-score, you'd use defence_score or defencescore instead. You can use upper case letters and dashes, but you have to use slightly more complicated synatx than I've described above so it's better just to not do that. In summary, this is the basic layout of a sheet worker. Every worker will look like this. on("change:stat1 change:stat2 sheet:opened", function() { getAttrs(["stat1", "stat2"], function(values) { const stat1 = +values.stat1||0; const stat2 = +values.stat2||0; // perform some calculation here
setAttrs({ destination_stat: calculation_result }); }); }); This assumes you are doing numerical calculations. If your stats dont need to be numbers, the const lines will be simpler, like this: const stat1 = values.stat1; const stat2 = values.stat2; The code in the full worker above (with the + ||0) makes sure the input is a number, and if it cant recognise it as a number, it sets a default value of 0. If you have several calculated stats, I can probably create a single function to make them all in one go, instead of having to create a separate sheet worker for each. But I'd need the details of how they are calculated, including attribute names. Almost forgot: Sheet workers must be put inside a script block. If your html doesnt have the code below, add it to the end of your character sheet: <script type="text/worker">
</script> All the sheet workers you create go inside that block.