It is possible to do it as a repeating section or as a static set of controls. To do your previous calculation using math.max, it could look like this on("sheet:opened change:agility change:equip1 change:equip2 change:equip3 change:equip4 change:equip5 change:equip6 change:maxagility1 change:maxagility2 change:maxagility3 change:maxagility4 change:maxagility5 change:maxagility6", function() { getAttrs(["agility","equip1","equip2","equip3","equip4","equip5","equip6","maxagility1","maxagility2","maxagility3","maxagility4","maxagility5","maxagility6"], function(values) { const agi = parseInt(values.agility,10)||0; const equ1 = parseInt(values.equip1,10)||0; const equ2 = parseInt(values.equip2,10)||0; const equ3 = parseInt(values.equip3,10)||0; const equ4 = parseInt(values.equip4,10)||0; const equ5 = parseInt(values.equip5,10)||0; const equ6 = parseInt(values.equip6,10)||0; const max1 = parseInt(values.maxagility1,10)||0; const max2 = parseInt(values.maxagility2,10)||0; const max3 = parseInt(values.maxagility3,10)||0; const max4 = parseInt(values.maxagility4,10)||0; const max5 = parseInt(values.maxagility5,10)||0; const max6 = parseInt(values.maxagility6,10)||0; let max = Math.min(agi,20); if(equ1 > 0) max = Math.min(max,max1); if(equ2 > 0) max = Math.min(max,max2); if(equ3 > 0) max = Math.min(max,max3); if(equ4 > 0) max = Math.min(max,max4); if(equ5 > 0) max = Math.min(max,max5); if(equ6 > 0) max = Math.min(max,max6); setAttrs({ maxagilityfinal: max }); }); }); I would write it a bit differently to make it more compact, but this way you should be able to understand what's happening. Math.min looks at the numbers supplied, and returns the smallest one. As a repeating section, you have the advantage that you can have any number of sets of armour. Here's one way to write that. i have assumed that the repeating section is called repeating_armor , and the relevant attributes are called maxagility , and equip . on("sheet:opened change:agility change:repeating_armor:equip change:repeating_armor:maxagility remove:repeating_armour", function() { getSectionIDs('repeating_armor', function(ids) { const fieldnames = []; // walk through each row of the repeating section, and create an equip and maxagility attribute name for each row.
// you need to do this so that when you use getAttrs, you have a valid list of attribute names
// since repeating sections change in use, you dont know what they'll be when writing the sheet.
ids.forEach(id => { fieldnames.push( `repeating_armor_${id}_equip`, // this inserts the current row id to the attribute name, so it is accurate. `repeating_armor_${id}_maxagility`, ); }); getAttrs(["agility",...fieldnames], function(values) {
//...fieldnames expands the array, so each item is put into the getattrs array with agility. const agi = parseInt(values.agility)||0; let max = Math.min(20,agi); // use the math.min function to select the minimum value of those supplied. // now walk through the row ids again, and get the equip and max from each row. ids.forEach(id => { const equip = parseInt(values[`repeating_armor_${id}_equip`])||0; const maxagility = parseInt(values[`repeating_armor_${id}_maxagility`])||0; // if the equip box is checked, check if maxagility is lower than current max. if(equip > 0) { max = Math.min(max, maxagility); } }); setAttrs({ maxagilityfinal: max }); }); }); });