
Hello Roll20
I am trying t o improve the AD&D 2E Revised character sheet. In my efforts I came across this issue. In the Currency section, there is a calculation for total GP value of gems. It looks like this:
The first row in the table does not calculate to the total counter in the bottom of the table. This is because the first row is a static row and the remaining rows are repeating. Here is the HTML code and the SheetWorker code:
HTML:
<h4>Gem Pouch</h4> <table> <tr> <td class="sheet-default-header" style="text-align:left;">Description</td> <td class="sheet-default-header">Value</td> <td class="sheet-default-header"># Held</td> <td class="sheet-default-header">Cut/Size</td> </tr> <tr> <td><input type="text" name="attr_gemdesc" title="@{gemdesc}" class="sheet-medium" placeholder="Item Name"></td> <td><input type="text" name="attr_gemvalue" title="@{gemvalue}" class="sheet-short" value="0" placeholder="GP"></td> <td><input type="number" name="attr_gemqty" title="@{gemqty}" class="sheet-short" value="0"></td> <td><input type="text" name="attr_gemsizecut" title="@{gemsizecut}" class="sheet-medium" placeholder="Size/Cut details"></td> </tr> </table> <fieldset name="repeating_gem" class="repeating_gem"> <table> <tr> <td><input type="text" name="attr_gemdesc" title="@{repeating_gem_$X_gemdesc}" class="sheet-medium" placeholder="Item Name"></td> <td><input type="text" name="attr_gemvalue" title="@{repeating_gem_$X_gemvalue}" class="sheet-short" placeholder="GP"></td> <td><input type="number" name="attr_gemqty" title="@{repeating_gem_$X_gemqty}" class="sheet-short" value="0"><input style="display: none;" type="text" name="attr_gemvaluetemp" class="sheet-short" value="0" disabled></td> <td><input type="text" name="attr_gemsizecut" title="@{repeating_gem_$X_gemsizecut}" class="sheet-medium" placeholder="Size/Cut details"></td> </tr> </table> </fieldset>
SheetWorker
//Standard Currency on('change:repeating_gem remove:repeating_gem', function(){ TAS.repeating('gem') .attrs('gemstotalvalue') .fields('gemvalue','gemqty','gemstotalvalue') .reduce(function(m,r){ m.gemvalue+=(r.F.gemvalue*r.I.gemqty); r.gemvaluetemp=(r.F.gemvalue*r.I.gemqty); return m; },{gemvalue:0, desc: []},function(m,r,a){ a.gemstotalvalue=m.gemvalue; }) .execute(); });
I can see the issue, that the sheet worker is only looking for changes in the repeating rows, and therefore obviously does not include any values from the static row.
I know that a "quick fix" would be to simply remove the one static row, and only use repeating rows. Then it would calculate all rows as expected. However since this is a preexisting sheet, I do not want to do that as I might remove data that various players has inputet in the first row. I would much rather improve the calculation to handle all the rows, static and repeating.
I am totally new to sheetworkers, and I am not a Pro user (so I have a Pro user upload my sheet for tests), so development is slow and roundtrips for tests are long. Also I have no idea how to debug sheetworkers, as I cannot seem to find the code in the Chrome DevTools.
If anyone knows how to modify the above sheet worker to also track the static row, and could give me a finished code snippet I would really appreciate it!
There are multiple other table sets of static and repeating rows throughout the sheet that has the same problem, so a fix here would mean 7 other fixes down the road :)