Advertisement Create a free account

[Help] to understand changing autocalc to sheetworker

My stupid question of the day: I am trying to change some autocalc on a sheet to using sheetworkers read the wiki however still not getting it to work, First we have .json file for translations Translation json "total-hitpoint": "Total Hitpoint", "temporary-hitpoint": "Temp. Hitpoint", "permanent-hitpoint": "Perm. Hitpoint", The code from our html HTML                     <tr> <td><span class="label" data-i18n="total-hitpoint">Total Hitpoint</span></td> <td colspan="2"><input type="number" name="attr_total_hitpoint" class="sheet-center" value="@{permanent_hitpoint}+@{temporary_hitpoint}" disabled="true"></td> </tr> <tr> <td><span class="label" data-i18n="temporary-hitpoint">Temp. Hitpoint</span></td> <td colspan="2"><input type="number" name="attr_temporary_hitpoint" value="0" class="sheet-center"></td> </tr> <tr> <td><span class="label" data-i18n="permanent-hitpoint">Perm. Hitpoint</span></td> <td colspan="2"><input type="number" name="attr_permanent_hitpoint" value="0" class="sheet-center"></td> </tr> Now to change it from a autocalc to sheetworker from my understanding if I read things right. I change HTML                     <tr> <td><span class="label" data-i18n="total-hitpoint">Total Hitpoint</span></td> <td colspan="2"><input type="number" name="attr_total_hitpoint" class="sheet-center" value="0" readonly="true"></td> </tr> <tr> <td><span class="label" data-i18n="temporary-hitpoint">Temp. Hitpoint</span></td> <td colspan="2"><input type="number" name="attr_temporary_hitpoint" value="0" class="sheet-center"></td> </tr> <tr> <td><span class="label" data-i18n="permanent-hitpoint">Perm. Hitpoint</span></td> <td colspan="2"><input type="number" name="attr_permanent_hitpoint" value="0" class="sheet-center"></td> </tr> < script type = " text/worker " > on("change:th change:ph sheet:opened", function() { getAttrs(["temporary_hitpoint","permanent_hitpoint"], function(values) { let th = parseInt(values.temporary_hitpoint,10)||0; let ph = parseInt(values.permanent_hitpoint,10)||0; let thp = th + ph; setAttrs({ total_hitpoint: tsp }); }); }); </ script > but so far thats not working ( I can change the values on the character sheet of   temporary _hitpoint  and  permanent _hitpoint  but  total_hitpoint    is remaining 0 and of course I cant change because it is now readonly but should be updating by sheetworkers if i was correct so what am I doing wrong please.
1562817648

Edited 1562817673
GiGs
Pro
Sheet Author
The translation file can be ignored when dealing with sheet workers. All that sheet workers care about is the attr names. It looks like your problem is the on(change) line. You need to give the attribute names there, so it should be on("change:temporary_hitpoint change:permanent_hitpoint sheet:opened", function() { getAttrs(["temporary_hitpoint","permanent_hitpoint"], function(values) { let th = parseInt(values.temporary_hitpoint,10)||0; let ph = parseInt(values.permanent_hitpoint,10)||0; let thp = th + ph; setAttrs({ total_hitpoint: thp }); }); }); You also had a typo in the setattrs section - tsp instead of thp .
Thank you so much GiG's That helps so much (its working now) I now understand what I was doing wrong. 
1562855940
GiGs
Pro
Sheet Author
Great :)