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

JS for Repeating Values in Sheetworker

1613603157

Edited 1613607225
I can't find a good tutorial on how the sheetworker parses repeating values. I've been working with some toy code, and I'm starting to see some values appearing, but I'm not sure how to implement anything yet. Hopefully you all can steer me in the right course. So, here is what I'm working with in this toy problem; A repeating field called repeating_powers A set of three radio buttons with values 0, 1, and 2 with the name attr_ranktype A final value to be calculated from all of the attr_ranktype &nbsp;radio buttons pressed. For our purposes, lets call the attribute it will be pass to as attr_foo Lets assume I only have five instances of my repeating table. Note that I know this example could be solved with the RepeatingSum function I'll link to at the end of this paragraph. The problem is that the lookups I have to do for my actual problem make using RepeatingSum not an option. But, if you come across this post looking for answers, check here first to see if it will work for you;&nbsp; <a href="https://wiki.roll20.net/RepeatingSum" rel="nofollow">https://wiki.roll20.net/RepeatingSum</a> Here is where I am so far, with comments on what I understand; HTML &lt;fieldset class="repeating_powers"&gt; //Some code here that is not important at this time //A collection of my three radio buttons &lt;input type="radio" class="sheet-isDefault" value="0" name="attr_ranktype" checked&gt; &lt;span class='sheet-boxTitle'&gt;Default Rank &lt;/span&gt; &lt;input type="radio" class="sheet-isRank" value="1" name="arrt_ranktype"&gt; &lt;span class='sheet-boxTitle'&gt;Power Rank &lt;/span&gt; &lt;input type="radio" class="sheet-isBase" value="2" name="attr_ranktype"&gt; &lt;span class='sheet-boxTitle'&gt;Baseline Rank &lt;/span&gt; //Some more code &lt;/fieldset&gt; JS on("sheet:opened change:repeating_powers:powerrank change:repeating_powers:powerrank change:repeating_powers:basecost change:repeating_powers:rankcost change:repeating_powers:baserankcost change:repeating_powers:baserankvalue change:repeating_powers:rankbasestat remove:repeating_powers", function(){ getSectionIDs("repeating_powers", function(idarray) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//If I have no repeating powers, then just stop what I'm doing now and exit &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (idarray.length === 0) { &nbsp;&nbsp;&nbsp;&nbsp; return; &nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Build an array of my ranktypes &nbsp;&nbsp;&nbsp;&nbsp;const fieldArray = []; &nbsp;&nbsp;&nbsp;&nbsp; idarray.forEach(id =&gt; fieldArray.push( &nbsp;&nbsp;&nbsp;&nbsp; `repeating_powers_${id}_ranktype` &nbsp;&nbsp;&nbsp;&nbsp; )); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//So, if I were to look at fieldArray[0], it would give me a value like &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//"repeating_powers_-asdjfbniujsadk234klnlk34_ranktype" which is the unique &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//row identifier &nbsp;&nbsp;&nbsp;&nbsp;var firstRankTypeValue; //I eventually want to have this give me the value of my [0] element ranktype &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var lastRankTypeValue; //I eventually want to have this give me the value of my [4] element ranktype&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var sumRankTypeValue; //I eventually want to have this give me the value of my [0]-[4] elements in some sort of for loop &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//From here, I have no idea how to actually pull the values correctly with a getAttrs and a setAttrs, though I know I have to use a function(values) with my getAttrs }); }); Additionally, lets say at some point I need to do 2+ values in my fieldArray. Say, for example, I also need to pass the amount of dice I am rolling, as below; //Build an array of my ranktypes and die amounts &nbsp;&nbsp;&nbsp;&nbsp;const fieldArray = []; &nbsp;&nbsp;&nbsp;&nbsp; idarray.forEach(id =&gt; fieldArray.push( &nbsp;&nbsp;&nbsp;&nbsp; `repeating_powers_${id}_ranktype`, `repeating_powers_${id}_dieamount` &nbsp;&nbsp;&nbsp;&nbsp; )); How would this change getAttrs and setAttrs if I had a variable like... var diemoded; //A modded amount of dice where it is equal to ranktype * dieamount Sorry if this is a lot to ask, but hopefully my examples are helpful. Thanks in advance for any help!
Also going to note, I made sure that repeating section's attributes have unique names within them and I made sure all of the names are lowercase and include no underscores.
1613605727
GiGs
Pro
Sheet Author
API Scripter
If the html you've posted above is exactly as in your sheet you have a very important typo &lt;input type="radio" class="sheet-isRank" value="1" name=" arrt _ranktype"&gt; &lt;span class='sheet-boxTitle'&gt;Power Rank &lt;/span&gt; should be &lt;input type="radio" class="sheet-isRank" value="1" name=" attr _ranktype"&gt; &lt;span class='sheet-boxTitle'&gt;Power Rank &lt;/span&gt; In jour JS, the event line you have powerrank twice: change:repeating_powers:powerrank change:repeating_powers:powerrank and I dont see ranktype anywhere. What does this mean? Lets assume I only have three instances of my repeating table. So, I cant tell exactly what you are trying to do, but here's the structure of the minimum code you need: on ( 'sheet:opened&nbsp; change:repeating_powers:ranktype change:repeating_powers:d ieamount &nbsp;remove:repeating_powers' ,&nbsp; function (){ &nbsp;&nbsp;&nbsp;&nbsp; getSectionIDs ( 'repeating_powers' ,&nbsp; function ( idarray )&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //If&nbsp;I&nbsp;have&nbsp;no&nbsp;repeating&nbsp;powers,&nbsp;then&nbsp;just&nbsp;stop&nbsp;what&nbsp;I'm&nbsp;doing&nbsp;now&nbsp;and&nbsp;exit &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if &nbsp;( idarray . length &nbsp;===&nbsp; 0 )&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Build&nbsp;an&nbsp;array&nbsp;of&nbsp;my&nbsp;ranktypes &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const &nbsp; fieldArray &nbsp;=&nbsp;[]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; idarray . forEach ( id &nbsp; =&gt; &nbsp; fieldArray . push ( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `repeating_powers_ ${ id } _ranktype`, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `repeating_powers_ ${ id } _dieamount` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;you&nbsp;now&nbsp;have&nbsp;an&nbsp;array&nbsp;of&nbsp;the&nbsp;ranktype names across all rows,&nbsp;and&nbsp;you&nbsp;use&nbsp;getAttrs&nbsp;to&nbsp;get&nbsp;the&nbsp;values &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getAttrs ( fieldArray ,&nbsp; function ( values ){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;whatever&nbsp;working&nbsp;you&nbsp;need&nbsp;to&nbsp;do&nbsp;goes&nbsp;in&nbsp;here. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;}); }); I'd like to fill in the rest but I dont understand what you are trying to do. I dont follow this code: &nbsp;&nbsp;&nbsp;&nbsp;var firstRankTypeValue; //I eventually want to have this give me the value of my [0] element ranktype &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var lastRankTypeValue; //I eventually want to have this give me the value of my [2] element ranktype&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var sumRankTypeValue; //I eventually want to have this give me the value of my [0]-[2] elements in some sort of for loop Can you describe everything &nbsp;you want the sheet worker to do, with all relevant attribute names and the data type they ocntain?
1613606264

Edited 1613606800
GiGs
Pro
Sheet Author
API Scripter
on reflection, I am wondering if there's a misunderstanding of how radio input values work. With this code &lt;input type="radio" class="sheet-isDefault" value="0" name="attr_ranktype" checked&gt; &lt;span class='sheet-boxTitle'&gt;Default Rank &lt;/span&gt; &lt;input type="radio" class="sheet-isRank" value="1" name="attr_ranktype"&gt; &lt;span class='sheet-boxTitle'&gt;Power Rank &lt;/span&gt; &lt;input type="radio" class="sheet-isBase" value="2" name="attr_ranktype"&gt; &lt;span class='sheet-boxTitle'&gt;Baseline Rank &lt;/span&gt; you have one attribut, ranktype, which has a value of 0, 1, or2, depending on which is selected. You never need to check the [0], [1], or [2] values - there is only one value, whichever equals whichever is selected. You can never have more than one of these buttons pressed. As soon as you click one, it will deselect another. On the other hand, if you want to sum all the ranktypes across all the rows, that would look like this (there's better ways to write this code, but I'm expecting you do need to do more so this works as a decent template): on ( 'sheet:opened&nbsp;change:repeating_powers:ranktype&nbsp;remove:repeating_powers' ,&nbsp; function (){ &nbsp;&nbsp;&nbsp;&nbsp; getSectionIDs ( 'repeating_powers' ,&nbsp; function ( idarray )&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //If&nbsp;I&nbsp;have&nbsp;no&nbsp;repeating&nbsp;powers,&nbsp;then&nbsp;just&nbsp;stop&nbsp;what&nbsp;I'm&nbsp;doing&nbsp;now&nbsp;and&nbsp;exit &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if &nbsp;( idarray . length &nbsp;===&nbsp; 0 )&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Build&nbsp;an&nbsp;array&nbsp;of&nbsp;my&nbsp;ranktypes &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const &nbsp; fieldArray &nbsp;=&nbsp;[]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; idarray . forEach ( id &nbsp; =&gt; &nbsp; fieldArray . push ( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `repeating_powers_ ${ id } _ranktype` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;you&nbsp;now&nbsp;have&nbsp;an&nbsp;array&nbsp;of&nbsp;the&nbsp;attribute&nbsp;names,&nbsp;and&nbsp;you&nbsp;use&nbsp;getAttrs&nbsp;to&nbsp;get&nbsp;the&nbsp;values &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getAttrs ( fieldArray ,&nbsp; function ( values ){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;whatever&nbsp;working&nbsp;you&nbsp;need&nbsp;to&nbsp;do&nbsp;goes&nbsp;in&nbsp;here. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;say&nbsp;you&nbsp;want&nbsp;to&nbsp;sum&nbsp;all&nbsp;the&nbsp;ranktype&nbsp;attribute&nbsp;values,&nbsp;loop&nbsp;through&nbsp;each&nbsp;row. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;create&nbsp;an&nbsp;attribute&nbsp;to&nbsp;save&nbsp;the&nbsp;final&nbsp;attributes&nbsp;before&nbsp;updating&nbsp;the&nbsp;sheet. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const &nbsp; output &nbsp;=&nbsp;{}; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;now&nbsp;loop&nbsp;through&nbsp;the&nbsp;rows&nbsp;again,&nbsp;and&nbsp;add&nbsp;up&nbsp;the&nbsp;ranktype&nbsp;values &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let &nbsp; sum &nbsp;=&nbsp; 0 ; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; idarray . forEach ( id &nbsp; =&gt; &nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const &nbsp; ranktype &nbsp;=&nbsp; parseInt ( values [ `repeating_powers_ ${ id } _ranktype` ])&nbsp;||&nbsp; 0 ; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sum &nbsp;=&nbsp; sum &nbsp;+&nbsp; ranktype ; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;now&nbsp;we&nbsp;have&nbsp;looped&nbsp;through&nbsp;all&nbsp;the&nbsp;rows,&nbsp;and&nbsp;have&nbsp;a&nbsp;sum,&nbsp;we&nbsp;want&nbsp;to&nbsp;save&nbsp;it&nbsp;to&nbsp;the&nbsp;character&nbsp;sheet. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; output . foo &nbsp;=&nbsp; sum ; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setAttrs ( output ); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;}); });
1613607136

Edited 1613607433
GiGs said: If the html you've posted above is exactly as in your sheet you have a very important typo &lt;input type="radio" class="sheet-isRank" value="1" name=" arrt _ranktype"&gt; &lt;span class='sheet-boxTitle'&gt;Power Rank &lt;/span&gt; should be &lt;input type="radio" class="sheet-isRank" value="1" name=" attr _ranktype"&gt; &lt;span class='sheet-boxTitle'&gt;Power Rank &lt;/span&gt; In jour JS, the event line you have powerrank twice: change:repeating_powers:powerrank change:repeating_powers:powerrank and I dont see ranktype anywhere. What does this mean? Lets assume I only have three instances of my repeating table. So, I cant tell exactly what you are trying to do, but here's the structure of the minimum code you need: on ( 'sheet:opened&nbsp; change:repeating_powers:ranktype change:repeating_powers:d ieamount &nbsp;remove:repeating_powers' ,&nbsp; function (){ &nbsp;&nbsp;&nbsp;&nbsp; getSectionIDs ( 'repeating_powers' ,&nbsp; function ( idarray )&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //If&nbsp;I&nbsp;have&nbsp;no&nbsp;repeating&nbsp;powers,&nbsp;then&nbsp;just&nbsp;stop&nbsp;what&nbsp;I'm&nbsp;doing&nbsp;now&nbsp;and&nbsp;exit &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if &nbsp;( idarray . length &nbsp;===&nbsp; 0 )&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Build&nbsp;an&nbsp;array&nbsp;of&nbsp;my&nbsp;ranktypes &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const &nbsp; fieldArray &nbsp;=&nbsp;[]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; idarray . forEach ( id &nbsp; =&gt; &nbsp; fieldArray . push ( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `repeating_powers_ ${ id } _ranktype`, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `repeating_powers_ ${ id } _dieamount` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;you&nbsp;now&nbsp;have&nbsp;an&nbsp;array&nbsp;of&nbsp;the&nbsp;ranktype names across all rows,&nbsp;and&nbsp;you&nbsp;use&nbsp;getAttrs&nbsp;to&nbsp;get&nbsp;the&nbsp;values &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getAttrs ( fieldArray ,&nbsp; function ( values ){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;whatever&nbsp;working&nbsp;you&nbsp;need&nbsp;to&nbsp;do&nbsp;goes&nbsp;in&nbsp;here. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;}); }); I'd like to fill in the rest but I dont understand what you are trying to do. I dont follow this code: &nbsp;&nbsp;&nbsp;&nbsp;var firstRankTypeValue; //I eventually want to have this give me the value of my [0] element ranktype &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var lastRankTypeValue; //I eventually want to have this give me the value of my [2] element ranktype&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var sumRankTypeValue; //I eventually want to have this give me the value of my [0]-[2] elements in some sort of for loop Can you describe everything &nbsp;you want the sheet worker to do, with all relevant attribute names and the data type they ocntain? OK, lets tackle this in the easily missed bits of me being a bad poster first... The attr &nbsp;and arrt&nbsp; &nbsp;were some fat-finger mistakes. Fixing now. powerrank &nbsp;twice was a copy-paste error I missed. Fixing now For my actual event handler, it works fine when it should be working. I just threw it in there to have something. Your notation is appreciated, though, but it not the source of my woes. By three instances of my repeating stucture, I mean I have three repeating powers. I now realize how that can be confusing with the three radio buttons. Lets say instead I have 5 instances repeating powers, giving me instances [0]-[4]. I'll adjust the mentions in my code above to make this more clear. But, hey, we can skip all that and go right to the good news. It turns out in my actual code that I used a single quotation mark as opposed to a backtick. For the sake of completeness, I'm going to do a follow-up code with some assumed values so maybe people can use it for reference if they come across this post. Much to your credit, GiGs, I never would have noticed if I didn't look up a diff on what you had and what I had. My current IDE makes it VERY hard to tell the difference between ' and `. Do you have any recommendations on IDEs?
1613607616
GiGs
Pro
Sheet Author
API Scripter
I use visual studio Code, but its not great for operating on roll20 sheet workers in a HTML page. I have to copy the sheet workers out into separate JS files to get the intellisense and syntax highlighting to work properly.&nbsp; Are you saying you have several different repeating sections each called repeating_powers? Is there a reason you have given them the same name and not different names?
1613607687

Edited 1613609457
repeating_powers block on the sheet Index ranktype value dieamount value 1st 0 1 2 2nd 1 0 3 3rd 2 2 3 4th 3 1 5 5th 4 2 4 CODE (Please excuse some tabbing issues. The copy/paste was a tad unfriendly.) on('sheet:opened change:repeating_powers:ranktype change:repeating_powers:dieamount remove:repeating_powers', function(){ getSectionIDs('repeating_powers', function(idarray) { //If I have no repeating powers, then just stop what I'm doing now and exit //In this example, we will have an idarry length of 5 if (idarray.length === 0) { return; } //This will build an array containing all of my ranktype and dieamount values. Since there are 5 values, //the index will go from [0] to [4] const fieldArray = []; idarray.forEach(id =&gt; fieldArray.push( `repeating_powers_${id}_ranktype`, `repeating_powers_${id}_dieamount` )); &nbsp;&nbsp;&nbsp;&nbsp;// you now have an array of the ranktype names across all rows, and you use getAttrs to get the values &nbsp;&nbsp;&nbsp;&nbsp; getAttrs(fieldArray, function(values){ let firstRankTypeValue = 0; //I eventually want to have this give me the value of my [0] ranktype let lastRankTypeValue = 0; //I eventually want to have this give me the value of my [4] ranktype &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let sumRankTypeValue = 0; //I eventually want to have this give me the sum of my [0]-[4] ranktype let sumRankDie = 0; //I eventually want to have this give the sum of the product of all ranktypes and dieamounts at each index idarray.forEach(id =&gt; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const ranktype = parseInt(values[`repeating_powers_${id}_ranktype`])||0; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const diemoded = parseInt(values[`repeating_powers_${id}_diemoded`])||0; //If first index if (id === 0){ firstRankTypeValue = ranktype; } //If last index if (id === (idarray.length -1)){ lastRankTypeValue = ranktype; } //Do unconditional work. sumRankTypeValue = sumRankTypeValue + ranktype; sumRankDie = sumRankDie + (ranktype * diemoded); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); setAttrs({ "foo_first_rank": firstRankTypeValue, "foo_last_rank": lastRankTypeValue, "foo_rank_sum": sumRankTypeValue, "foo_product_rank_die": sumRankDie }); &nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;}); }); RESULTS "foo_first_rank" = 1 "foo_last_rank" = 2 "foo_rank_sum" = 6 "foo_product_rank_die" = 21
1613607754

Edited 1613610479
GiGs said: I use visual studio Code, but its not great for operating on roll20 sheet workers in a HTML page. I have to copy the sheet workers out into separate JS files to get the intellisense and syntax highlighting to work properly.&nbsp; Are you saying you have several different repeating sections each called repeating_powers? Is there a reason you have given them the same name and not different names? No, just that I have done the "Add" option 5 times, in that I will have 5 indexes to work across. A finite example, if you will. I've been working in Notepad++, and they syntax has been lacking here as well since the js is all inline. I should really make a new tab for JS and also adjust the font for better backtick recognition. Just switched to Zenburn in Notepad++ with the JS language and it is MUCH better!
1613608201
GiGs
Pro
Sheet Author
API Scripter
Eric M. said: No, just that I have done the "Add" option 5 times, in that I will have 5 indexes to work across. A finite example, if you will. So its a repeating section with exactly 5 'rows' ? Does it always have exactly 5 rows? For a structure like that, its usually better to hard code 5 copies of the relevant html (and add _0, _1, etc, to relevant attribute name). The code is easier to work with, and you dont have to deal with players adding extra rows or deleting important ones.
1613608312

Edited 1613609319
GiGs said: Eric M. said: No, just that I have done the "Add" option 5 times, in that I will have 5 indexes to work across. A finite example, if you will. So its a repeating section with exactly 5 'rows' ? Does it always have exactly 5 rows? For a structure like that, its usually better to hard code 5 copies of the relevant html (and add _0, _1, etc, to relevant attribute name). The code is easier to work with, and you dont have to deal with players adding extra rows or deleting important ones. No, not always. I'm just using it as a finite example to be able to verify the math works correctly. Please see accompanying table a few posts back for the example data. I just wanted to work with a concreate example as opposed to an abstract, mostly because I find it easier to expand upon examples that have finite solutions. In actually, they can have between 0 - ??? repeating_powers blocks, giving me an unknown number of indexes. Everything is just &nbsp;different enough in Roll20 than from what I'm used to doing that it always seems to throw me on a kilter. I appreciate your responses and patience, GiGs! I do have everything working with the toy code I posed above and the given variables in the example table.
1613626206

Edited 1613626241
GiGs
Pro
Sheet Author
API Scripter
This code isnt quite right: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (id === 0){ firstRankTypeValue = ranktype; } //If last index if (id === (idarray.length -1)){ lastRankTypeValue = ranktype; } The id given by forEach is the actual row id, not the index within the idarray array. So neither of those should ever by true - are you getting proper values out of that? It is possible to get the index using forEach, like this idarray.forEach((id, index)&nbsp;=&gt;&nbsp;{ And then you could do &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (index === 0){ firstRankTypeValue = ranktype; } //If last index if (index === (idarray.length -1)){ lastRankTypeValue = ranktype; } But there's a possibly better way to handle your particular situation. Here's a tweaked version of your worker (changes are all inside the getAttrs): on ( 'sheet:opened&nbsp;change:repeating_powers:ranktype&nbsp;change:repeating_powers:dieamount&nbsp;remove:repeating_powers' ,&nbsp; function (){ &nbsp;&nbsp;&nbsp;&nbsp; getSectionIDs ( 'repeating_powers' ,&nbsp; function ( idarray )&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //If&nbsp;I&nbsp;have&nbsp;no&nbsp;repeating&nbsp;powers,&nbsp;then&nbsp;just&nbsp;stop&nbsp;what&nbsp;I'm&nbsp;doing&nbsp;now&nbsp;and&nbsp;exit &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //In&nbsp;this&nbsp;example,&nbsp;we&nbsp;will&nbsp;have&nbsp;an&nbsp;idarry&nbsp;length&nbsp;of&nbsp;5 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if &nbsp;( idarray . length &nbsp;===&nbsp; 0 )&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //This&nbsp;will&nbsp;build&nbsp;an&nbsp;array&nbsp;containing&nbsp;all&nbsp;of&nbsp;my&nbsp;ranktype&nbsp;and&nbsp;dieamount&nbsp;values.&nbsp;Since&nbsp;there&nbsp;are&nbsp;5&nbsp;values, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //the&nbsp;index&nbsp;will&nbsp;go&nbsp;from&nbsp;[0]&nbsp;to&nbsp;[4] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const &nbsp; fieldArray &nbsp;=&nbsp;[]; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; idarray . forEach ( id &nbsp; =&gt; &nbsp; fieldArray . push ( &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `repeating_powers_ ${ id } _ranktype` , &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `repeating_powers_ ${ id } _dieamount` &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;you&nbsp;now&nbsp;have&nbsp;an&nbsp;array&nbsp;of&nbsp;the&nbsp;ranktype&nbsp;names&nbsp;across&nbsp;all&nbsp;rows,&nbsp;and&nbsp;you&nbsp;use&nbsp;getAttrs&nbsp;to&nbsp;get&nbsp;the&nbsp;values &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getAttrs ( fieldArray ,&nbsp; function ( values ){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;add&nbsp;a&nbsp;function&nbsp;to&nbsp;do&nbsp;the&nbsp;parseInt&nbsp;operation&nbsp;with&nbsp;less&nbsp;typing. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const &nbsp; int &nbsp;=&nbsp;( value ,&nbsp; error &nbsp;=&nbsp; 0 )&nbsp; =&gt; &nbsp; parseInt ( value )&nbsp;||&nbsp; error ; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;get&nbsp;the&nbsp;first&nbsp;and&nbsp;last&nbsp;values. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const &nbsp; firstRankTypeValue &nbsp;=&nbsp; int ( values [ `repeating_powers_ ${ idarray [ 0 ] } _ranktype` ]);&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const &nbsp; lastRankTypeValue &nbsp;=&nbsp; int ( values [ `repeating_powers_ ${ idarray [ idarray . length &nbsp;- 1 ] } _ranktype` ]); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp;initialise&nbsp;variables&nbsp;for&nbsp;counting&nbsp;in&nbsp;the&nbsp;loop. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let &nbsp; sumRankTypeValue &nbsp;=&nbsp; 0 ;&nbsp; //the&nbsp;sum&nbsp;of&nbsp;my&nbsp;[0]-[4]&nbsp;ranktype&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let &nbsp; sumRankDie &nbsp;=&nbsp; 0 ;&nbsp; //the&nbsp;sum&nbsp;of&nbsp;the&nbsp;product&nbsp;of&nbsp;all&nbsp;ranktypes&nbsp;and&nbsp;dieamounts&nbsp;at&nbsp;each&nbsp;index &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; idarray . forEach ( id &nbsp; =&gt; &nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const &nbsp; ranktype &nbsp;=&nbsp; int ( values [ `repeating_powers_ ${ id } _ranktype` ]); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const &nbsp; diemoded &nbsp;=&nbsp; int ( values [ `repeating_powers_ ${ id } _diemoded` ]); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sumRankTypeValue &nbsp;=&nbsp; sumRankTypeValue &nbsp;+&nbsp; ranktype ; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sumRankDie &nbsp;=&nbsp; sumRankDie &nbsp;+&nbsp;( ranktype &nbsp;*&nbsp; diemoded ); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setAttrs ({ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'foo_first_rank' : &nbsp; firstRankTypeValue , &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'foo_last_rank' : &nbsp; lastRankTypeValue , &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'foo_rank_sum' : &nbsp; sumRankTypeValue , &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'foo_product_rank_die' : &nbsp; sumRankDie &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}); &nbsp;&nbsp;&nbsp;&nbsp;}); });
Awesome. Thank you again!
Of note, I have not seen any code on the forums like sumRankTypeValue += ranktype , with people opting not to use "+=". Is this an operator that Roll20 doesn't like?
1613673350

Edited 1613780982
GiGs
Pro
Sheet Author
API Scripter
That works fine in roll20. I specifically avoided it above because i didnt&nbsp; want&nbsp; to include code that was more confusing, if you werent familiar with it.
Nah, we use a lot of that type of syntax in Mark Logic. Maybe I'm getting too soft doing NoSQL that my OOP is getting rusty.