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

Calculating weight and value with charged items.

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.
Maybe enter the wand in the inventory once with its weight, then make another inventory entry for the charges with a weight of 0?
I'm a little confused.  I am not sure how that fixes the problem?
1512206201

Edited 1512206436
Jakob
Sheet Author
API Scripter
I don't know how TAS works, but it looks like the calculation is in this row: return r.F.weight*r.I.qty; //< calculate the weight for the row (could have used the totalweight) You could probably change this to return different things depending on r.I.qty_max being larger than 1 or not, and it might solve your problem. EDIT: and same for the row where it calculates the value: m+=(r.I.qty*r.F.value); //< Generate a running cost
1512308953
chris b.
Pro
Sheet Author
API Scripter
yes where Jakob says, you should put an if statement right before which is what we did on later versions of the sheet: if (r.I.qty_max >1 ) { //just add value or weight dont' multiply by qty } else { //your current calculation }