
Hello Roll20 experts. Context for the problem I am trying to make a field that shows a player how many proficiency points they have left to spend. I have an input field where the player is suggested to put a macro to calculate a value. I would like to read the value outputted by the macro in a sheet worker, to do my additional calculations. The reason why I am trying to do this with a sheetworker, is because the character sheet is already loaded with UI-thread calculations, making the entire sheet pretty slow. Therefore I am trying to focus on keeping calculations in the backend thread, thus making the sheet more responsive. The calculations also include values from repeating fields, so that also require sheet workers. The HTML looks something like this (shorted down for clarity): <!-- The input field for the macro -->
<input type="text" name="attr_profslotstotal" title="@{profslotstotal}" class="sheet-display" value="4+floor(@{level-class1}/3)+@{intlang}"/>
<!-- The disabled input field for the macro's calculated value -->
<input type="text" name="attr_profslotstotalcalc" value="[[@{profslotstotal}]]" style="display: none;" disabled />
<!-- The output field for the remaining points -->
<input type="text" name="attr_profslotsremain" title="@{profslotsremain}" class="sheet-short" placeholder="Slots" value="0" readonly/>
<fieldset name="repeating_profs" title="@{profs}" class="repeating_profs">
<table class="sheet-table-white">
<tr>
<td><input type="text" name="attr_profname" title="@{repeating_profs_$X_profname}" placeholder="Name of NonWepProf"></td>
<td><input type="number" name="attr_profslots" title="@{repeating_profs_$X_profslots}" class="sheet-short" placeholder="Slots"></td>
<td><input type="text" name="attr_profstatnum" title="@{repeating_profs_$X_profstatnum}" placeholder="@{abilityScore}" class="sheet-maxtext"></td>
<td>&plusmn;</td>
<td><input type="text" name="attr_profmod" title="@{repeating_profs_$X_profmod}" value="0" class="sheet-short"></td>
<td><button type="roll" name="roll_Prof" title="%{repeating_profs_$X_Prof}" value="/roll [[1d20cs<1cf>20]]&le;[[(@{profstatnum})+(@{profmod})]] @{profname}"></button></td>
</tr>
</table>
</fieldset> Here is the sheet worker: on('change:repeating_profs remove:repeating_profs change:profslotstotalcalc', function(){
TAS.repeating('profs')
.attrs('profslotsremain','profslotstotalcalc')
.fields('profslots')
.reduce(function(m,r){
m.profslots+=(r.I.profslots);
return m;
},{profslots:0, desc: []},function(m,r,a){
a.profslotsremain=(a.I.profslotstotalcalc-m.profslots);
})
.execute();
}); My plan was to have a single disabled field, calculated on the UI-thread, to calculate the value of the macro. This is the field profslotstotalcalc . Then I would listen to that field for changes with the sheet worker. Thus whenever the player grew enough levels for the value in the macro to change, then the calculated field would update its value, and this would trigger the sheet worker. The problem narrowed down After a lot of trial and error, I realized that the profslotstotalcalc field cannot be read from a sheet worker. Apparently, fields that are marked with disabled and thus auto-calculating, is not placed in Attributes & Abilities section of the sheet. This means that a sheet worker, cannot read the value of the field and therefore always reads the field to be empty or 0 depending on how the field is read. Solutions? Does anyone have a solution for reading the calculated value of a macro with a sheet worker? I know I could turn the calculations around, so that I sum all the repeating fields to a hidden field (just like the profslotstotalcalc field) and then calculate the remaining points with a disabled auto-calculating field. However I would prefer to keep as much logic as possible in the sheet worker if possible, so any solution that can eliminate the usage of a hidden disabled field is highly appreciated.