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

Summing values in a repeating field

1483974681
GiGs
Pro
Sheet Author
API Scripter
I have a  repeating field called repeating_passions. one of the fields is name=attr_PassionValue I need to sum up all those passions that have a value of 16 or higher. So if I had 4 passions, with values 14, 16, 17, and 12, the result would be 33. Is there a way to loop through the rows of a repeating field and check and sum the value of a field like this?
1483986482
chris b.
Pro
Sheet Author
API Scripter
Look at Aaron's TAS (The Aaron Sheet) module. it has pretty easy to use sum functions for repeating sections. You can plug this into your sheet. Note: this only works with sheetworkers. You can't really create sum fields for repeating sections. without javascript. He has some documentation and description of how to use it, just do a search for "TAS" on this site to get the latest posts.
1483988918
GiGs
Pro
Sheet Author
API Scripter
Thanks for the suggestion. Unfortunately I cant make head nor tail of that. I see there's a simple sum function, but since I need to only sum values that are 16 or higher, I cant use it, and don't know how to build the function I need.
1483990013
Finderski
Plus
Sheet Author
Compendium Curator
G G said: Thanks for the suggestion. Unfortunately I cant make head nor tail of that. I see there's a simple sum function, but since I need to only sum values that are 16 or higher, I cant use it, and don't know how to build the function I need. Are the other values actually important if they don't have to be summed? What I mean is, if 12 is the same as 0, I'd just put a 0 in the field unless it was 16+.
1483991929
GiGs
Pro
Sheet Author
API Scripter
Yes, they are scores that are rolled against. In the system, passions are rated on 1-20 or higher. Values of 16+ are exceptional, and grant bonus glory equal to their stat, which must be totalled up. Scores below 16 give 0 glory, but are still stats that can be rolled against.
1483992738
GiGs
Pro
Sheet Author
API Scripter
I have a partially working sheet worker, that looks like this function gloryFamous(traitValue) {     var result = 0;     if(traitValue>15) { result = traitValue; }     return result; } function GloryFromPassions() {     return function() {         getAttrs(["LoyaltyLiege", "LoveFamily","Hospitality","Honor", "HateSaxons","glory_passions"], function(v) {             var iglory = 0;             iglory = iglory + gloryFamous(parseInt(v.LoyaltyLiege));             iglory = iglory + gloryFamous(parseInt(v.LoveFamily));             iglory = iglory + gloryFamous(parseInt(v.Hospitality));             iglory = iglory + gloryFamous(parseInt(v.Honor));             iglory = iglory + gloryFamous(parseInt(v.HateSaxons));             getSectionIDs("repeating_passions", function(idarray) {                 for(var i=0; i < idarray.length; i++) {                  //Do something with the IDs                     var ID = idarray[i];                     getAttrs([                         "repeating_passions"+ID+"_passion-value"                     ],function(values){                         iglory = iglory + gloryFamous(parseInt(values["repeating_passions"+ID+"_passion-value"]));                                                                       });                 }             });                          setAttrs({                 "glory_passions": iglory             });         });     }; } on("change:loyaltyliege", GloryFromPassions()); on("change:lovefamily", GloryFromPassions()); on("change:hospitality", GloryFromPassions()); on("change:honor", GloryFromPassions()); on("change:hatesaxons", GloryFromPassions()); on("change:repeating_passions", GloryFromPassions()); The problem is that I dont understand what I'm doing. The getSectionIDs section does nothing. 
1483996698
GiGs
Pro
Sheet Author
API Scripter
I broke the getsectionids part out into a seperate function, and found a script sample in the LeaguesOfAdventures character sheet that helped me get that working. here's the sample, for the record. //Inventory weight tallying         on("change:repeating_equipment:equipweight remove:repeating_equipment", function (e) {             getSectionIDs("repeating_equipment", function (idarr) {                 var totalWeight = 0;                 var weightTally = _.after(idarr.length, function () {                     setAttrs({ invweight: Math.round(totalWeight) });                 });                 for (var i = 0; i < idarr.length; i++) {                     getAttrs(["repeating_equipment_" + idarr[i] + "_equipweight"], function (v) {                         totalWeight += parseFloat(v[Object.keys(v)[0]]);                         weightTally();                     });                 }             });         });
1483999322
vÍnce
Pro
Sheet Author
G G said: I broke the getsectionids part out into a seperate function, and found a script sample in the LeaguesOfAdventures character sheet that helped me get that working. here's the sample, for the record. //Inventory weight tallying         on("change:repeating_equipment:equipweight remove:repeating_equipment", function (e) {             getSectionIDs("repeating_equipment", function (idarr) {                 var totalWeight = 0;                 var weightTally = _.after(idarr.length, function () {                     setAttrs({ invweight: Math.round(totalWeight) });                 });                 for (var i = 0; i < idarr.length; i++) {                     getAttrs(["repeating_equipment_" + idarr[i] + "_equipweight"], function (v) {                         totalWeight += parseFloat(v[Object.keys(v)[0]]);                         weightTally();                     });                 }             });         }); Thanks for that. +1 I've been beating my head against getSectionIDs all weekend...
1484044825

Edited 1484044847
GiGs
Pro
Sheet Author
API Scripter
Glad to help! The wiki is not very helpful with its example of "do stuff here" with no indication how to do stuff. A complete working example would have been very example.