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 with conditionals in RepeatingSum

I've added an "Active" checkbox to a repeating list of powers because many powers that impact stats are not always on &amp; may take an action or a portion of movement, etc. to activate, have a power cost, turn off when the character is unconscious, etc., so it's useful to be able to toggle them off and cascade the stat update through the rest of the sheet. For this checkbox inside the repeater: &lt; input &nbsp; type = 'checkbox' &nbsp; name = 'attr_power_active' &nbsp; title = 'power_active' &nbsp; checked &nbsp;&nbsp; /&gt; ... I've updated a previously working RepeatingSum call to filter certain items using the checkbox, similar to what's shown in the conditional sums example at <a href="https://wiki.roll20.net/RepeatingSum" rel="nofollow">https://wiki.roll20.net/RepeatingSum</a>. &nbsp;&nbsp;&nbsp;&nbsp;on('change:repeating_powers&nbsp;remove:repeating_powers',&nbsp;function()&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;repeatingSum(["abilityip_total",&nbsp;"st_adj_total",&nbsp;"en_adj_total",&nbsp;"ag_adj_total",&nbsp;"in_adj_total",&nbsp;"cl_adj_total","init_adj_total",&nbsp;"pwr_adj_total",&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"hp_adj_total",&nbsp;"luck_adj_total",&nbsp;"ability_cp_total","atk_all_total","atk_1_total","atk_2_total","atk_3_total","atk_4_total","atk_5_total", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"atk_6_total","atk_7_total","atk_8_total","atk_9_total"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"powers", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ip_cost", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["st_adj","power_active"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["en_adj",&nbsp;"power_active"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["ag_adj",&nbsp;"power_active"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["in_adj",&nbsp;"power_active"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["cl_adj",&nbsp;"power_active"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["init_adj","power_active"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["pwr_adj",&nbsp;"power_active"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["hp_adj","power_active"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["luck_adj","power_active"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ability_cost", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["atk_all_adj","power_active"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["atk_1_adj","power_active"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["atk_2_adj","power_active"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["atk_3_adj","power_active"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["atk_4_adj","power_active"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["atk_5_adj","power_active"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["atk_6_adj","power_active"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["atk_7_adj","power_active"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["atk_8_adj","power_active"], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;["atk_9_adj","power_active"] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]); &nbsp;&nbsp;&nbsp;&nbsp;}); Now however, the conditional items never update - i.e. the checkbox value appears to always be interpreted as zero. Any ideas what's going wrong? Full html is at <a href="https://github.com/drl2/roll20-character-sheets/blob/mighty_protectors/Villains%20and%20Vigilantes/VandVMightyProtectors.html" rel="nofollow">https://github.com/drl2/roll20-character-sheets/blob/mighty_protectors/Villains%20and%20Vigilantes/VandVMightyProtectors.html</a>
1596536507

Edited 1596536980
GiGs
Pro
Sheet Author
API Scripter
I guess the problem is this part: [ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'ip_cost' , &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'st_adj' , 'power_active' ], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'en_adj' ,&nbsp; 'power_active' ], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'ag_adj' ,&nbsp; 'power_active' ], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'in_adj' ,&nbsp; 'power_active' ], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'cl_adj' ,&nbsp; 'power_active' ], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'init_adj' , 'power_active' ], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'pwr_adj' ,&nbsp; 'power_active' ], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'hp_adj' , 'power_active' ], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'luck_adj' , 'power_active' ], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'ability_cost' , &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'atk_all_adj' , 'power_active' ], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'atk_1_adj' , 'power_active' ], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'atk_2_adj' , 'power_active' ], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'atk_3_adj' , 'power_active' ], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'atk_4_adj' , 'power_active' ], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'atk_5_adj' , 'power_active' ], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'atk_6_adj' , 'power_active' ], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'atk_7_adj' , 'power_active' ], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'atk_8_adj' , 'power_active' ], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ 'atk_9_adj' , 'power_active' ] &nbsp;&nbsp;&nbsp;&nbsp;]); The function isnt designed to handled nested arrays like that - though honestly, it should be. It's a much more sensible syntax, and I'll try to find time to update repeatingSum to use that synax sometime in the future. In the meantime, you need to do that with two repeatingSum Calls - one where everything is multiplied by power_active, and one where they aren't. Like so (line breaks included for readability): on ( 'change:repeating_powers&nbsp;remove:repeating_powers' ,&nbsp; function ()&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp; repeatingSum ([ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'st_adj_total' ,&nbsp; 'en_adj_total' ,&nbsp; 'ag_adj_total' ,&nbsp; 'in_adj_total' ,&nbsp; 'cl_adj_total' , &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'init_adj_total' ,&nbsp; 'pwr_adj_total' ,&nbsp; 'hp_adj_total' ,&nbsp; 'luck_adj_total' ,&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'atk_all_total' , 'atk_1_total' , 'atk_2_total' , 'atk_3_total' , 'atk_4_total' , 'atk_5_total' , &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'atk_6_total' , 'atk_7_total' , 'atk_8_total' , 'atk_9_total' &nbsp;&nbsp;&nbsp;&nbsp;], &nbsp;&nbsp;&nbsp;&nbsp; 'powers' , &nbsp;&nbsp;&nbsp;&nbsp;[ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'st_adj' , 'en_adj' , 'ag_adj' , 'in_adj' , 'cl_adj' , &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'init_adj' , 'pwr_adj' , 'hp_adj' , 'luck_adj' , &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'atk_all_adj' , 'atk_1_adj' , 'atk_2_adj' , 'atk_3_adj' , 'atk_4_adj' , 'atk_5_adj' , &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'atk_6_adj' , 'atk_7_adj' , 'atk_8_adj' , 'atk_9_adj' , &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'power_active' &nbsp;&nbsp;&nbsp;&nbsp;]); }); on ( 'change:repeating_powers&nbsp;remove:repeating_powers' ,&nbsp; function ()&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp; repeatingSum ([ 'abilityip_total' ,&nbsp; 'ability_cp_total' ],&nbsp; 'powers' ,&nbsp;[ 'ip_cost' ,&nbsp; 'ability_cost' ]&nbsp;); });
So by simply adding 'power_active' to the end of the original list of source fields, it will multiply all the other fields by that value?
1596551756
GiGs
Pro
Sheet Author
API Scripter
Thats correct - its set up to match each field in the first array with the second array, and any extra fields in the second array are multipliers to all. But your assumed syntax is a clearer way to do it, honestly, since it handles situations where they dont all get multipled by the same extra fields, so I'll incorporate that when I have the time.