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

Repeating Sections and Max Dex

So I'm creating a repeating section for Armor items and I want to include a Max Dex section. I'm unsure how to reference the section using sheet workers and other items to calculate max dex. I'm using The Aaron's Sheet for other summing but not sure how to do max dex. I created the following sheet worker to do it if I have 6 set fields for armor but I am not sure how to do it for a repeating section. 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; const min1 = Math.floor(((agi + (20-(equ1*(20-max1)))) - Math.abs( agi - (20-(equ1*(20-max1))))) / 2); const min2 = Math.floor(((min1 + (20-(equ2*(20-max2)))) - Math.abs( min1 - (20-(equ2*(20-max2))))) / 2); const min3 = Math.floor(((min2 + (20-(equ3*(20-max3)))) - Math.abs( min2 - (20-(equ3*(20-max3))))) / 2); const min4 = Math.floor(((min3 + (20-(equ4*(20-max4)))) - Math.abs( min3 - (20-(equ4*(20-max4))))) / 2); const min5 = Math.floor(((min4 + (20-(equ5*(20-max5)))) - Math.abs( min4 - (20-(equ5*(20-max5))))) / 2); const min6 = Math.floor(((min5 + (20-(equ6*(20-max6)))) - Math.abs( min5 - (20-(equ6*(20-max6))))) / 2); setAttrs({                             maxagilityfinal: min6 }); }); }); And that sheet worker above works great. I have a checkbox for Equipping the item and the game's max dexterity is 20. So it works great. Just can't get it to work for repeating sections as I'm not sure how to reference them. Thanks.
1580499092

Edited 1580499110
GiGs
Pro
Sheet Author
API Scripter
How do the repeating sections apply to max dex? Do you need to respond to one specific row change in the section, or do you need to count up values across several rows of the section? (The code for these two approaches is very different.)
1580499505
GiGs
Pro
Sheet Author
API Scripter
For the record, if you want to access a single row in a repeating section,  from within that row , you use on('change:repeating_sectionname:attributename', function() {     getAttrs['repeating_sectionname_attributename'], function(values) {         const att = parseInt(values.repeating_sectionname_attributename) ||0;      ));    }); Notice the different syntax on the change line compared to the other two lines. If you want to do something with the same attribute across multiple rows of a repeating section at once, you need to use the function getSectionIDs (described in the wiki).
1580499702
GiGs
Pro
Sheet Author
API Scripter
PS: that calculation seems incredibly complicated for an rpg stat. I have a feeling it can be massively simplified using the Math.min or Math.max function.
Thanks for the replies GiGs.  I am using a game that has armor, and shields and each of them has a maximum Agility (Dex) they can allow on a scale to 20. So I am just trying to find a way to get the minimum of what is equipped. I didn't know about the Math.min function myself actually. I was just using a math function to give me a minimum value. OR, if none of the armor is equipped. To default to max agility of 20 or the player's agility score. I'm just curious how I can parse the repeating section to give me that total if at all. Or if I'm better off with a static section.  If that makes any sense. Sorry. This is my first time creating a character sheet and ever using any of this stuff.
Here is a picture: What I want to do is make it so the Maximum Agility is Either 20, The player's Agility Score or the lowest of the equipped items.  Right now it works but I have those 6 fields set constant. I was just curious if that is possible to accomplish with a repeating section. 
1580503865

Edited 1580504058
GiGs
Pro
Sheet Author
API Scripter
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             });         });     }); });
Wow this is fantastic. I'm gonna spend some time trying to digest this. THANK YOU!
Quick question; When you say   // walk through each row of the repeating section, and create an equip and maxagility attribute name for each row. I guess I'm not 100% clear on what that entails. You say walk through each row alot and I'm just not familiar with what that really means. 
1580513533

Edited 1580513558
GiGs
Pro
Sheet Author
API Scripter
I just mean thats what the code is doing. It is creating a loop, and going through each item one by one ("walking through"). A repeating section might have 1 row, or 10 rows. The forEach function loops through each row, and while in each row, does something - whether creating the needed attribute rolls, or checking whether the attribute is lower than max.