I know this has been explained TAS on the forums many times, and there are a number of examples. One of which, I have been using for my inventory section for a long time. However, one of my players pointed out an error in the math. The qty is giving bad values for items that have charges. For example a wand that has 50/50 charges is showing up as a player having 50 wands. Obviously this messes up the value and weight. The repeating section uses qty_max to hold the max value for charges. I know how to fix this, but not with the TAS code. I was wondering if someone could give me some advice. on('change:repeating_item', function(){
// all of these operations could likely have been done in a single reduce operation, but
// doing them in multiple operations shows that this is something that can be done.
TAS.repeating('item')
.attrs('item_total_weight','item-total-value') //< getting the attributes for the totals
.fields('name','qty','qty_max','weight','value') //< specifying the fields we care about
// qty / qty_max is for charged items like scrolls and kits.
// I know what I need to do if this wasnt TAS, IF qty_max > 1 then "only count as 1 item no matter the value of 'qty'"
// but I dont know how to do that with this code.
.map(function(r){
return r.F.weight*r.I.qty; //< calculate the weight for the row (could have used the totalweight)
},function(m,r,a){
a.D[3].item_total_weight=_.reduce(m,function(m,v){ //<sum the array of total weights and set it on the total weight attribute
return m+v;
},0);
})
.reduce(function(m,r){
m+=(r.I.qty*r.F.value); //< Generate a running cost
r.D[2].runningtotal=m; //< set it for the current row (the running part)
return m;
},0,function(m,r,a){
a.D[2]['item-total-value']=m; //< take the final sum and set it on the total cost attribute
})
.execute(); //< begin executing the above operations
});
Hopefully, this question will be much less complicated than my last repeating section question.