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

[Sheet Worker] Change Button value in Repeating Section

1529417448
Davemania
KS Backer
Sheet Author
API Scripter
The goal is a button for players that outputs an Ability Command Button for the GM to whisper dice results to himself. I was able to do this easily outside of a repeating section, having the ability command button reference the roll on a hidden button that does the actual roll. <input type="text" name="attr_DSskillname" value="Adventuring Detect Secret" readonly> <input type="number" name="attr_DSskillvalue" value="18"> <button type="roll" value="[@{character_name} Detect Secret](~@{character_id}|gmDSThrow)" name="roll_DSThrow" title="Detect Secret Skill Throw"></button> <button type="roll" value="/w gm &{template:acks_template} {{name=@{DSskillname}}} {{skillthrow=[[1d20+(?{Modifier|0})]]}} {{target=[[@{DSskillvalue}]]}}" name="roll_gmDSThrow"></button> Now, I am trying to accomplish it with a list of abilities/skills/actions in a repeating section of the sheet, which is a little less straightforward as the ability command button value can’t reference the hidden button without the repeating id. So, I need to set it dynamically with a sheet worker, but I don’t think I can directly change a button value with a sheet worker. So a hidden attribute is introduced as well, and the button value is set to that attribute. Here are the bits for the repeating section and the sheetworker: <fieldset> <input type="text" name="attr_gmskillname" placeholder="Skill Name"> <input type="number" name="attr_gmskillvalue" value="18"> <input type="hidden" name="attr_gmskillRollvalue"> <button type="roll" value="@{gmskillRollvalue}" name="roll_GMThrow"></button> <button type="roll" value="/w gm &{template:acks_template} {{name=@{gmskillname}}} {{skillthrow=[[(1d20+?{Modifier|0})]]}} {{target=[[@{gmskillvalue}]]}}" name="roll_gmGMThrow"></button> </fieldset> //Update GMSkill buttons roll values sometimes I guess on("change:repeating_gmskills:gmskillname", function() { getSectionIDs("gmskills", function(idArray) { var rollvalues = {}; for(var i=0; i < idArray.length; i++) { rollvalues["gmskills_" + idArray[i] + "_gmskillRollvalue"] = "[@{character_name} @{repeating_gmskills_" + idArray[i] + "_gmskillname}](~@{character_id}|repeating_gmskills_" + idArray[i] + "_gmGMThrow)"; } setAttrs(rollvalues); }); }); I can see the attributes fill in on the character sheet once the event is triggered, and I know that the buttons are tied to those attributes, but clicking the buttons does... nothing. No errors generated or anything, just nothing. If I drag a button to the macro bar and press it, it generates an empty line in chat. On the Attributes and Abilities tab, if I copy the value that is being generated from one of the attributes into an ability macro and execute it, it works! Hopefully someone has some insight into this!
1529421555

Edited 1529421921
GiGs
Pro
Sheet Author
API Scripter
The things that jump out at me: your fieldset doesnt seem to have a name: <fieldset class="repeating_gmskills"> And your getSectionIDs is missing the "repeating_" on("change:repeating_gmskills:gmskillname", function() { getSectionIDs("repeating_gmskills", function(idArray) { Notice also inside your for loop, rollvalues omits the "repeating_" before gmskills, but you do use it after the equals sign, so you aren't matching up those values correctly. "repeating_" is part of the fieldset's attribute name, you can't omit it.
1529425239

Edited 1529425272
Davemania
KS Backer
Sheet Author
API Scripter
Thank you for pointing out what I could not see! lack of a class for fieldset was an error I made when copying to the forum, I do have that in place on my sheet. According to the documentation I could find on getSectionIDs, the 'repeating_ ' is omitted. However, you are absolutely correct, I was missing the 'repeating_' portion in my rollvalues for setAttrs. Putting that in makes it work like I always wanted!
1529426082
GiGs
Pro
Sheet Author
API Scripter
Glad to help! That's pretty weird it works when repeating is omitted in getSectionIDs. I have always used it in mine. I notice  on the wiki , it is inconsistent - directly under the getSectionIds it omits it, but a couple of paragraphs later it includes it. I'd recommend including it to be safe.
1529426455
Davemania
KS Backer
Sheet Author
API Scripter
It is weird; I just verified that it functions with or without 'repeating_' in the getSectionIDs call. Definitely gonna go ahead and leave it in there, though.