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

Referencing Attributes in Repeating Rows for Roll Button

I thought for sure this would be covered somewhere but I've been tinkering and researching for hours so I'm sorry if this is already covered. I have a repeating row and on that row is: A name field A number field (for rank) A text field that calculates a text based on the rank (1=d4, 2=d6, 3=d8, etc) via a sheet worker A roll button to roll the die that has already been correctly calculated with the sheet worker I am having trouble getting the roll button to reference the attribute that is calculated via sheet worker. <div> <h1>Physique</h1> <label>Physique:<input type="number" name="attr_physique" max="10" min="1" /><span name="attr_physique_die"></span></label> <h3>Abilties</h3> <fieldset class="repeating_pabil"> Name:<input type="text" name="attr_pabilname" /> Rank:<input type="number" name="attr_pabilrank" max="10" min="0" /><span type="text" name="attr_dice"></span><button type='roll' name='roll_phys' value='/roll ?{Amount of Effort}@{dice}kh1'>Roll</button> </fieldset> </div> The above code takes in the rank number and the sheet worker is posting the corresponding die to the attr_dice span and posting it so I can tell the sheet worker is doing its job and setting repeating_pabil_$n_dice to the correct value. However, the roll button won't appropriately use the attr_dice.  Other threads have said that within the row, I should not have to specify the row index so @{dice} should reference the dice attribute from that row but I get an error saying that doesn't exist. If I use @{repeating_pabil_$0_dice} it will properly use the attribute I have set up but then I run into another problem where the next row also uses index 0.  I can't figure out how to just make it reference the row that it's in one way or the other and I feel like I'm out of ideas for trying to fix it.  Any advice would be appreciated.  It seems like it should be really simple. Just in case it is relevant this is my sheetworker: // Calculate Die for each Physique Ability on("change:repeating_pabil:pabilrank", function() { getAttrs(["repeating_pabil_pabilrank"], function(values) { setAttrs({ repeating_pabil_dice: GetDice(values.repeating_pabil_pabilrank) }); }); }); and the accompanying GetDice() function: // Function to determine dice value // function GetDice(level) { let die=""; if (level <=1) { die='d4'; } else if (level <=2) { die='d6'; } else if (level <=3) { die='d8'; } else if (level <=4) { die='d10'; } else if (level <=10) { die='d12'; } return die; }
1581949230
GiGs
Pro
Sheet Author
API Scripter
I'm not seeing any reason why this shouldnt work. It's possible "dice" is tripping over some restricted keyword, or classhing with another attribute name. Try changing its name to "pabildice" for consistency with the other attributes in the fieldset. Your getDice function can be simplified, btw. // Function to determine dice value // function GetDice(level) {   let die="d12"; if (level <=1) { die='d4'; } else if (level <=2) { die='d6'; } else if (level <=3) { die='d8'; } else if (level <=4) { die='d10'; } return die; } Since it cant be above 10, just set that as the default, and check for the others. There's an even simpler way (you could do this on one line, but I've broken it out into the separate steps): function GetDice(level) {      let levelnum = parseInt(level) || 1;         let size = Math.min(12,2 * levelnum +2);    return "d" + size; }
Thank you GiGs for the reply, I will try your fix when I get back from work.  I also appreciate the advice on cleaning up the code.  I have it the way it is because I'm going to be adding things in to the other levels later on and it's not just linear but it has shown me some ways to simplify other areas of my sheet.  I'll let you know how it goes!
Unfortunately it still does not work. // Calculate Die for each Physique Ability on("change:repeating_pabil:pabilrank", function() { getAttrs(["repeating_pabil_pabilrank"], function(values) { setAttrs({ repeating_pabil_pabilDie: GetDice(values.repeating_pabil_pabilrank) }); }); }); // Function to determine dice value // function GetDice(level) { let die=""; if (level <=1) { die='d4'; } else if (level <=2) { die='d6'; } else if (level <=3) { die='d8'; } else if (level <=4) { die='d10'; } else if (level <=10) { die='d12'; } return die; } <div> <h1>Physique</h1> <label>Physique:<input type="number" name="attr_physique" max="10" min="1" /><span name="attr_physique_die"></span></label> <h3>Abilties</h3> <fieldset class="repeating_pabil"> Name:<input type="text" name="attr_pabilname" /> Rank:<input type="number" name="attr_pabilrank" max="10" min="0" /><span type="text" name="attr_pabilDie"></span><button type='roll' name='roll_phys' value='/roll ?{Amount of Effort}@{attr_pabilDie}kh1'>Roll</button> </fieldset> </div> Thinking it might be the word "dice" as you indicated I changed in to pabilDie.  This is having the same effect.  I cannot call the ability in that row with "pabilDie" or "attr_pabilDie".  I can  call it with repeating_pabil_$0_pabilDie but then I am locked to only rolling for the first repeating section.  I'm not sure if there is a variable I can insert instead of "$0" to grab its current row or not?  This is so frustrating because the span is correctly grabbing the die value.
1582792334

Edited 1582792783
I recently ran into the same problem too. I was able to solve it by adding the attribute in question as a hidden field in addition to the span. So I think this should fix it assuming we had the same problem. <div> <h1>Physique</h1> <label>Physique:<input type="number" name="attr_physique" max="10" min="1" /><span name="attr_physique_die"></span></label> <h3>Abilties</h3> <fieldset class="repeating_pabil">      <input type='hidden' name='attr_pabilDie' value='0' /> Name:<input type="text" name="attr_pabilname" /> Rank:<input type="number" name="attr_pabilrank" max="10" min="0" /><span type="text" name="attr_pabilDie"></span><button type='roll' name='roll_phys' value='/roll ?{Amount of Effort}@{attr_pabilDie}kh1'>Roll</button> </fieldset> </div> I think Roll20 can only correctly parse repeating field attributes with input elements that have the html value attribute during a roll event.
Thanks Kevin!  It's been a while so I actually redesigned how I worked the entire sheet.  If I need to go back it will be good to know what I need to do.  Thanks a bunch!