Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

adding up repeating fields

1594751041
Tealk
Pro
Sheet Author
Hello everyone, i would like to add up a repeating field, i found an example from Dark Heresy, but somehow it doesn't work and i don't see my mistake. Maybe someone can help me. here the repeating field <div class="sheet-totalxp"> <div class="sheet-formular"> <label for="attr_XPtoSpend">Verfügbare EP</label> <input type="number" class="sheet-number-20" name="attr_XPtoSpend"  value="@{XPTotal} - @{XPSpent}" disabled /> </div> <div class="sheet-formular"> <label for="attr_XPSpent">Ausgegebene EP</label> <input type="number"  class="sheet-number-20" name="attr_XPSpent" disabled /> </div> <div class="sheet-formular"> <label for="attr_XPTotal">Gesamte EP</label> <input type="number" class="sheet-number-20" name="attr_XPTotal" /> </div> </div> <fieldset class="repeating_advancements"> <div class="sheet-item"> <input name="attr_advancement1" type="text"> </div> <div class="sheet-brackets"> <input name="attr_advancement1xp" type="text"> </div> <div class="sheet-item"> <input name="attr_advancement2" type="text"> </div> <div class="sheet-brackets"> <input name="attr_advancement2xp" type="text"> </div> <div class="sheet-item"> <input name="attr_advancement3" type="text"> </div> <div class="sheet-brackets"> <input name="attr_advancement3xp" type="text"> </div> </fieldset> here the js part on('change:repeating_advancements', function(){     TAS.repeating('advancements')           .attrs('XPSpent')           .fields('advancement1xp','advancement2xp', 'advancement3xp')  .reduce(function(memo, row) { memo += (row.I.advancement1xp); memo += (row.I.advancement2xp); memo += (row.I.advancement3xp); return memo; },0,function(memo, row, attrSet) { attrSet.I.XPSpent = memo; }) .execute();  });
1594754897
Justin V.
Pro
Sheet Author
Translator
Hi Tealk, i'm using the same script in on my sheet. but my worker is a bit different. Try this on('change:repeating_advancements', function(){     TAS.repeating('advancements')  //< set the repeating group we are using         .attrs('XPSpent')  //< specify we want access to the total_weight attribute         .fields('advancement1xp', 'advancement2xp', 'advancement3xp') //< specify we want the item and weight repeating fields          .reduce(function(memo,row,attrSet,id,rowSet)         { memo.total += row.I.advancement1xp; memo.total += row.I.advancement2xp; memo.total += row.I.advancement3xp; return memo;         },{total: 0},function(memo,rowSet,attrSet)         {             attrSet.I.XPSpent = memo.total;         })         .execute();  });
1594755115
Justin V.
Pro
Sheet Author
Translator
Sorry, also for this to work you need Aaron's TAS script in your html too.. that's probably the issue. <a href="https://github.com/shdwjk/TheAaronSheet/blob/master/TheAaronSheet.js" rel="nofollow">https://github.com/shdwjk/TheAaronSheet/blob/master/TheAaronSheet.js</a>
1594755597

Edited 1594755649
Tealk
Pro
Sheet Author
do I just copy the whole thing or can I link to it somehow?
1594756038
Justin V.
Pro
Sheet Author
Translator
Yes, copy whole thing in, it needs to be before the repeating worker i believe, mine is anyway.
1594757340
Tealk
Pro
Sheet Author
Thanks for the help, now it works. But it's stupid with the script, because it takes so much space.
1594775815

Edited 1594775830
GiGs
Pro
Sheet Author
API Scripter
If you want a more compact approach, use this function:&nbsp; <a href="https://wiki.roll20.net/RepeatingSum" rel="nofollow">https://wiki.roll20.net/RepeatingSum</a>
1594785841
Tealk
Pro
Sheet Author
Thanks GiGs for the manual, somehow the search didn't give it to me. I will definitely have a look at it.