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

Help with sheetworker for repeating section

1575582227

Edited 1575582258
Pantoufle
Pro
Sheet Author
Translator
Hello, I copied some sheetworker scripts from somewhere I cannot recall in the forum and I struggle with it. Here is the sheetworker part : on("change:repeating_talents", function() { getSectionIDs("repeating_talents", function(idArray) { var rollvalues = {}; for(var i=0; i < idArray.length; i++) { rollvalues["repeating_talents_$" + idArray[i] + "_talent_row"] = "repeating_talents_$" + idArray[i] + "_talent_throw"; } setAttrs(rollvalues); }); }); Here is the related html : <fieldset class="repeating_talents"> <label>     <input type="text" name="attr_talent_name" placeholder="nom du talent" class="talent"> </label> <div class="grid grid-pc-attributes2" style="margin-bottom: 5px;">     <button name="roll_talent_throw" type="roll" value="&{template:face} {{name=@{character_name}}} {{rollname=@{talent_name}}} {{roll=[[@{talent_dice}]]}} {{reroll=@{talent_row}}}">         <h2><span type="text" name="attr_talent_name"></span></h2> <input type="hidden" name="attr_talent_row" value="0"> <span type="number" name="attr_talent_dice" class="attrmod"></span>                         </button>   <label>         <span>Dé</span> <select name="attr_talent_dice" type="text" placeholder="1d4" style="width: 6em"> <option value="0d0"></option> <option value="1d4">1d4</option> <option value="1d6">1d6</option> <option value="1d8">1d8</option> <option value="1d10">1d10</option> <option value="1d12">1d12</option> <option value="1d14">1d14</option> <option value="1d16">1d16</option> <option value="1d18">1d18</option> <option value="1d20">1d20</option> </select>             </label>          </div> </fieldset> what I want to achieve with the script : Set the value of the hidden input talent_row to repeating_talents_$i_talent_throw (i, ranging from 0 to... whatever) THX for reading :) have a nice day ! Pantoufle
1575615423

Edited 1575636688
GiGs
Pro
Sheet Author
API Scripter
There are a couple of problems I see. First the programming error:  rollvalues["repeating_talents_$" + idArray[i] + "_talent_row"] =  "repeating_talents_$" + idArray[i] + "_talent_throw"; As you probably know, there is a format you can use to call repeating section attributes in macros, which looks like this: "repeating_talents_$0_talent_throw" "repeating_talents_$1_talent_throw" //etc But that format is only  for macros. It doesnt work in sheet workers. You can also use the real  row id, which look something like  -zgfyte7569dhw6 . Calling a row with this would look like "repeating_talents_ -zgfyte7569dhw6 _talent_throw" Notice there is no $ character. The getSectionIDs function gives you an array of the real row ids, those big masses of letters and numbers which look like -zgfyte7569dhw6. So your code above would be creating something like rollvalues["repeating_talents_$-zgfyte7569dhw6_talent_row"] =  "repeating_talents_$-zgfyte7569dhw6_talent_throw"; Both sides of the equals sign have invalid values. If you want to make this work, you need both an idarray variable for the left side, and a simple count (1, 2, 3) for the right side. Your for loop already provides these, so you just need to change that line of code to rollvalues["repeating_talents_" + idArray[i] + "_talent_row"] = "repeating_talents_$" + i + "_talent_throw"; Note: removing the $ from the left side, so that it returns a valid attribute name, and removing idarray at the right side so it produces a valid name usable in macros. That will fix the code, but there's a big conceptual problem here. See next post. Edit:  I misunderstood what you were doing here - so cross out that last line.
1575616030

Edited 1575632980
GiGs
Pro
Sheet Author
API Scripter
Looking at your code, I think  I understand what the hidden talent_row attribute is meant to do. You are building an attribute to use in a reroll button, right? In that case, you dont need to use the $ format for either side in that case. the right side would use the same format as the left, like so: "repeating_talents_" + idarray[i] + "_talent_throw" You just need to remove the $ character. Does your rolltemplate build the rest of the code needed for the reroll button?
1575634979
Pantoufle
Pro
Sheet Author
Translator
Thx GiGs! I'll try your correction this afternoon and let you know! But I had the $ because it wasn't working... so I tried (wasnt sure if the function returns the number or the "true" id :p thx for clarifying) Right now the hidden attribute is set to 0. So I guesd there is another bug :D  Yes I'm trying to make a reroll button! And yes the roll template create the button (works for nonrepeating.. tricky for repeating :D).
1575636519

Edited 1575636635
GiGs
Pro
Sheet Author
API Scripter
just to clarify then, the line should be rollvalues["repeating_talents_" + idArray[i] + "_talent_row"] = "repeating_talents_" + idArray[i] + "_talent_throw"; Pantoufle  said: Right now the hidden attribute is set to 0. So I guesd there is another bug :D  Thats because 0 is the default. Your sheet worker wasnt touching that attribute, because an invalid name was being given. 
1575641112
Pantoufle
Pro
Sheet Author
Translator
Ok... it makes perfect sense :D And it does work now ^^ Greattttt !!! THX GiGs ! :)
1575641797
GiGs
Pro
Sheet Author
API Scripter
Great :)