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

Problem with sum of repeating rows

April 15 (3 years ago)
.Hell
Sheet Author

Hey, I posted this issue already in the CharSheet section but this might be the better place. If anyone can help with this you would make me happy :)

https://app.roll20.net/forum/post/9987337/problem-with-sum-of-repeating-rows

April 16 (3 years ago)

Edited April 16 (3 years ago)
David
Sheet Author

Use the Aaron Sheet. https://github.com/shdwjk/TheAaronSheet  it does all the work for you. Specifically the simple sum https://github.com/shdwjk/TheAaronSheet#example-1-tasrepeatingsimplesum


April 16 (3 years ago)
.Hell
Sheet Author

Thanks for the tip. I looked into it and did it as follows:

on('change:repeating_armors remove:repeating_armors', function() {
TAS.repeating('armors') //< set the repeating group we are using
.attrs('armor_total') //< specify we want access to the total_weight attribute
.fields('armorvalue','armorworn') //< specify we want the item and weight repeating fields
.execute(); //< tell TAS it has been configured and can run now.
});


But it does not work. Further tips are apprectiated

April 25 (3 years ago)
.Hell
Sheet Author

Anyone got any idea what I might be missing?

April 26 (3 years ago)

Edited April 26 (3 years ago)
vÍnce
Pro
Sheet Author

Stupid question; the complete TAS is installed within your sheetworker script right?

I am not skilled with sheetworkers but...  see if this works. 

on('change:repeating_armors remove:repeating_armors', function(){
    TAS.repeating('armors')
    .attrs('armor_total')
    .fields('armorvalue', 'armorworn')
    .reduce(function(m,r){
        m.armorvalue+=(r.F.armorvalue*r.I.armorworn);
        r.D[0].armor_total=(r.F.armorvalue*r.I.armorworn);
        return m;
    },
    {armorvalue:0,armorworn:0, desc: []}, function (m,r,a){
        a.armor_total=m.armorvalue;
    })
    .execute();
});


April 26 (3 years ago)
.Hell
Sheet Author

Thanks vince,

with your help and little modification of your snippet I got it mostly to run.

on('change:repeating_armors remove:repeating_armors', function(){
TAS.repeating('armors')
.attrs('armor_total')
.fields('armorvalue', 'armorworn')
.reduce(function(m,r){
if(r.armorworn === "on") {
m.armorvalue += r.F.armorvalue;
}
return m;
},
{armorvalue:0,armorworn:0, desc: []}, function (m,r,a){
a.armor_total=m.armorvalue;
})
.execute();
});

The last problem left is, that the field where I display the calculated value is not allowed to be disabled. If it is disabled the value is not updated...

April 26 (3 years ago)
.Hell
Sheet Author

The solution for the updating problem is:

  • the field is NOT disabled
  • the CSS class of the field to update needs
    pointer-events: none;
April 26 (3 years ago)
vÍnce
Pro
Sheet Author

Great.  I think you can also use a readonly input for your total attribute.