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

[help] TAS repeating section simplesum problem

1539535514
Yui V.
Pro
Sheet Author
Hello, I have already implanted the Tas script to sum up values in different repeating sections of my character sheet, and use that sum elswhere, no problem here, it works wonders. However, I'm trying to sum up the total price values of items in an inventory repeating section, and when I try the same thing as I already did with other values on my sheet, it doesn't work. This price value is in itself obtained by a non-script way, @{#}*@{$}, and I highly suspect that this is the problem. It seems to me that the TAS.repeatingSimpleSum does not understand the multiplication, and only accepts purely numerical values. If this is true, then I need a way to have the script multiply quantity by price for each row, and then add thes results together. The problem is: I know no javascript so I have no idea how to do that. Here are the three values I'm working with: <fieldset class="repeating_equip">      <div class="sheet-col">         <input type="number" style=" background: #FFF; width: 40px; height: 24px; border-radius: 2px;" name="attr_quantequip" value="0" /> </div> <div class="sheet-col">     <input type="number" style=" background: #FFF; width: 40px; height: 24px; border-radius: 2px;" name="attr_prixequip" value="0" /> </div> <div class="sheet-col">     <input type="number" name="attr_totprixequip" value="(@{quantequip}*@{prixequip})" disabled="true" style="background-color: transparent; border: transparent ; font-weight: bold; width: 40px;" data-formula="(@{quantequip}*@{prixequip})"/>     </div> </fieldset> What I tried with the scipt was : on('change:repeating_equip', function(){ TAS.repeatingSimpleSum('equip','totprixequip','total_prix'); }); </script> <div class="total">Total prix<br><input class="sumtotalprix" type="text" name="attr_total_prix" value="0" title="total prix" /></div> Which doesn't work.  I think I need to find a way to get the script to multiply, as I said, ``@{quantequip}`` by ``@{prixequip}`` for each row and then add the results with something like repeatingsimplesum, setting the value of the ```@{total_prix}`` attribute. I there a way to do that?
1539536914

Edited 1539536987
Pat S.
Forum Champion
Sheet Author
You could take a look at my sheet &nbsp;to see how I did the inventory weight. I had to take the quantity and the weight of each then combine it. After that I had to added item sum together to display it. I believe it is all about using the reduce function to make it work. I have threads scattered about for my sheet when I needed help with something similar you are doing. Code snippet from line 653 &lt;!--inventory weight calculation--&gt; // Equipment Carried Section // <a href="https://app.roll20.net/users/877778/sfx" rel="nofollow">https://app.roll20.net/users/877778/sfx</a> helped me with the following two sheet workers on('change:repeating_inventtab1', function(){ &nbsp; &nbsp; TAS.repeating('inventtab1') &nbsp; &nbsp; .attrs('tempweight') &nbsp; &nbsp; .fields('itemwornenc', 'itemquantity') &nbsp; &nbsp; .reduce(function(m,r){ &nbsp; &nbsp; &nbsp; &nbsp; m.itemwornenc+=(r.F.itemwornenc*r.I.itemquantity); &nbsp; &nbsp; &nbsp; &nbsp; r.D[0].tempweight=(r.F.itemwornenc*r.I.itemquantity); &nbsp; &nbsp; &nbsp; &nbsp; return m; &nbsp; &nbsp; },{itemwornenc:0,itemquantity:0, desc: []}, function (m,r,a){ &nbsp; &nbsp; a.tempweight=m.itemwornenc; &nbsp; &nbsp; }) &nbsp; &nbsp; .execute(); }) on('sheet:opened', function(){ &nbsp; &nbsp; TAS.repeating('inventtab1') &nbsp; &nbsp; .attrs('tempweight') &nbsp; &nbsp; .fields('itemwornenc', 'itemquantity') &nbsp; &nbsp; .reduce(function(m,r){ &nbsp; &nbsp; &nbsp; &nbsp; m.itemwornenc+=(r.F.itemwornenc*r.I.itemquantity); &nbsp; &nbsp; &nbsp; &nbsp; r.D[0].tempweight=(r.F.itemwornenc*r.I.itemquantity); &nbsp; &nbsp; &nbsp; &nbsp; return m; &nbsp; &nbsp; },{itemwornenc:0,itemquantity:0, desc: []}, function (m,r,a){ &nbsp; &nbsp; a.tempweight=m.itemwornenc; &nbsp; &nbsp; }) &nbsp; &nbsp; .execute(); })
1539538684
Yui V.
Pro
Sheet Author
It works ! Thank you!
1539539043
Pat S.
Forum Champion
Sheet Author
You can thank SFX (he is credited in the code) for helping me with it. I've taken to crediting those that help me with the code as a way to say thanks for their help. Plus if I ever stop working and maintaining the sheet, it will give anyone that picks up the code someone to ask questions.
1539582542

Edited 1539582563
GiGs
Pro
Sheet Author
API Scripter
If you want to do this without relying on TAS (and thus making your sheet code a lot shorter), there's a function we created in another thread you can use: First form of the sheet worker: <a href="https://app.roll20.net/forum/permalink/6858201/" rel="nofollow">https://app.roll20.net/forum/permalink/6858201/</a> Second form:&nbsp; <a href="https://app.roll20.net/forum/permalink/6860513/" rel="nofollow">https://app.roll20.net/forum/permalink/6860513/</a> Both do the same thing. Second form is more compact, but harder to read if you're new to JS.&nbsp;