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

Find max value in repeating section

1710144862
Maïlare
Pro
Sheet Author
API Scripter
Hello, I try to find the max value of a column in a repeating section but I don't find any information about it. I want to find the max value of the CharacteristicPower column. How can I make it ? Thanks for your help. The code of the repeating section. <!--Repeating section of characteristics-->         < fieldset class = "repeating_characteristic" >             < div class = "dark-row" style = " margin-bottom: 2px;" >                 < div class = 'sheet-2colrow' >                     <!--Left column-->                     < div class = "sheet-col" style = " background-color: #B6D7A8; width: 650px; margin-right: 0px;" >                         < input class = "textbox" type = "text" name = "attr_CharacteristicName" value = "Name" style = " margin-left: 10px; width: 240px;" />                         < button type = "roll" title = "PowerRoll" name = "roll_CharacteristicProficiency" style = " margin-left: 15px;" value = "&{template:default} {{name=@{CharacterName} - @{CharacteristicName } }} {{Power=[[1d@{CharacteristicProficiency}]]}}" ></ button >                         < input class = "textbox" type = "number" name = "attr_CharacteristicProficiency" value = "0" />                         < button type = "roll" title = "ControlRoll" name = "roll_CharacteristicPower" style = " margin-left: 10px;" value = "&{template:default} {{name=@{CharacterName} - @{CharacteristicName } }} {{Proficiency=[[1d@{CharacteristicPower}]]}}" ></ button >                         < input class = "textbox" type = "number" name = "attr_CharacteristicPower" value = "0" style = " margin-left: 0px;" />                         < input class = "textbox" type = "number" name = "attr_CharacteristicMass" value = "0" style = " margin-left: 2px;" />                         < input class = "textbox" type = "number" name = "attr_CharacteristicLength" value = "0" />                         < input class = "textbox" type = "number" name = "attr_CharacteristicWidth" value = "0" style = " margin-left: 2px;" />                         <!--Total of values--> < input class = "textbox" type = "number" name = "attr_CharacteristicLevel" value = "" readonly = "readonly" />                     </ div >                     <!--Right column-->                     < div class = "sheet-col" style = " background-color: #FFE599; width: 492px; margin-left: 0px;" >                         < input class = "textbox" type = "number" name = "attr_CharacteristicQuantity" value = "0" style = " margin-left: 9px;" />                         < input class = "textbox" type = "number" name = "attr_CharacteristicDamage" value = "0" style = " margin-left: 12px;" />                         < input class = "textbox" type = "text" name = "attr_CharacteristicPosition" value = "Position" style = " width: 105px;" />                         < input class = "textbox" type = "text" name = "attr_CharacteristicDescription" value = "Description" style = " width: 260px;" />                         < input type = "hidden" name = "attr_CharacteristicQtyLevel" />                     </ div >                 </ div >             </ div >         </ fieldset >
1710148115

Edited 1710148243
vÍnce
Pro
Sheet Author
Hi Maïlare, I'm assuming by "max value" you want the highest value?  Something like this should work. Updates whenever " CharacteristicPower " is changed. Not sure what or how you want to use the highest value, but this will post an array of all the repeating CharacteristicPower values as well as the highest one to the console log. If you un-comment  "// output.highest_characteristic_power = highestValue;"  it will output to an html input called "highest_characteristic_power" or rename to whatever you need.  You'll need to add the input field of course. <script type="text/worker"> // GLOBAL const section_attribute = (section, id, field) => `repeating_${section}_${id}_${field}`; on('change:repeating_characteristic:characteristicpower', (eventInfo) => { getSectionIDs('repeating_characteristic', (idArray) => { const output = {}; const fields = []; idArray.forEach((id) => { fields.push(section_attribute('characteristic', id, 'CharacteristicPower')); }); getAttrs(fields, (v) => { const characteristicPowerArray = []; let characteristicPowerValue = 0; idArray.forEach((id) => { characteristicPowerValue = +v[section_attribute('characteristic', id, 'CharacteristicPower')] || 0; characteristicPowerArray.push(characteristicPowerValue); }); const highestValue = Math.max(...characteristicPowerArray); // shows all the values and the highest console.log(`characteristicPowerArray:${characteristicPowerArray} Highest value:${highestValue}`); // output.highest_characteristic_power = highestValue; setAttrs(output, {silent: true}); }); }); }); </script>
1710153685
Maïlare
Pro
Sheet Author
API Scripter
vignes said: Salut Maïlare, je suppose par "valeur max" que tu veux la valeur la plus élevée ?  Quelque chose comme ça devrait fonctionner. Se met à jour chaque fois que " CharacteristicPower " est modifié. Vous ne savez pas quoi ou comment vous souhaitez utiliser la valeur la plus élevée, mais cela publiera un tableau de toutes les valeurs répétitives de CharacteristicPower ainsi que la plus élevée dans le journal de la console. Si vous supprimez le commentaire "//output.highest_characteristic_power =highValue;" il affichera une entrée HTML appelée "highest_characteristic_power" ou sera renommé selon vos besoins. Vous devrez bien sûr ajouter le champ de saisie. <script type="text/worker"> // GLOBAL const section_attribute = (section, id, field) => `repeating_${section}_${id}_${field}`; on('change:repeating_characteristic:characteristicpower', (eventInfo) => { getSectionIDs('repeating_characteristic', (idArray) => { const output = {}; const field = []; idArray.forEach((id) => { field.push(section_attribute('characteristic', id, 'CharacteristicPower')); }); getAttrs(fields, (v) => { const featurePowerArray = []; let featurePowerValue = 0; idArray.forEach((id) = > { featurePowerValue = +v[section_attribute('characteristic', id, 'CharacteristicPower')] || 0; featurePowerArray.push(characteristicPowerValue); }); const highValue = Math.max(...characteristicPowerArray); // affiche toutes les valeurs et la plus élevée console.log(`characteristicPowerArray:${characteristicPowerArray} Highest value:${highestValue}`); // output.highest_characteristic_power = mosthighValue; setAttrs(output, {silent: true}); }); } ); }); </script> Hello, I want to set a html input with this value. And yes I want the highest value. Thanks, I will try this.