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 .
×
May your rolls be chill this holiday season!
Create a free account

Using a button and a value in repeating section to change a value outside of repeating section.

1599631758

Edited 1599693754
I do my best to answer my own questions, but I keep trying to do things I've never done before.  Unfortunately this is no exception. This is the worker.  It isn't actually creating any logs.  I'm not sure what's going on with that. // load melee attacks on('clicked:repeating_meleeAttacks:load_melee_attack', () => { getAttrs(['repeating_meleeAttacks_melee_attack_action_points'], values => { const pnd_act_pnt_chng = int(values.pending_action_point_change) + int(values.repeating_meleeAttacks_melee_attack_action_points); console.log( 'load melee attacks' + '\n', 'pending_action_point_change: ' + pnd_act_pnt_chng ); setAttrs({pending_action_point_change: pnd_act_pnt_chng}); }); }); This is the repeating section, with everything removed except for what the worker uses. <fieldset class="repeating_meleeAttacks"> <div class="expandable-section paleRedGradient"> <input class="expand-control" type="hidden" name="attr_melee_checkbox_expand" value="0"/> <div class="meleeAttacksTitleGrid"> <div class="mleapc blueBackground section"> <div class="fieldLabelCenter white blueBackground section">AP</div> <input class="field right manual24" name="attr_melee_attack_action_points" type="number" min='2'> </div> <div class="mlelde blueBackground blueBorderTop1 section"> <button class="buttonStyleTop load" name="act_load_melee_attack" type="action" style="float:right;">Load</button> </div> </div> </div> </fieldset> And this is the value to be changed. <div class="pendap blueBackground section"> <input class="field manual19" name="attr_pending_action_point_change" type="number" value='0'> </div>
1599634833

Edited 1599634890
GiGs
Pro
Sheet Author
API Scripter
I spot two immediate problems here, and both have the same fix. First, you have an upper case letter in the on(change) line of your sheet worker. You must not do that. Change this: on('clicked:repeating_meleeAttacks:load_melee_attack', () => { to this: on('clicked:repeating_meleeattacks:load_melee_attack', () => { That might get your sheet worker working, but you also have another problem: You have an upper case letter in your repeating section name. You must also not do that. Change this: <fieldset class="repeating_meleeAttacks"> to this <fieldset class="repeating_meleeattacks"> and change the sheet worker accordingly, and it should work. The first problem applies to all attribute names: no matter the case in the html, on the change line you must always use lower case. The second problem is specific to fieldset names: if you use upper case letters in the name, you will create problems with roll buttons and scripts that try to change that section.
This is super weird.  I've made the changes you suggested, but I still don't even see a log message.  I've even tried putting test log messages immediately after the on clicked line, but there are no log messages.  Weird. // load melee attacks on('clicked:repeating_meleeattacks:load_melee_attack', () => { getAttrs(['repeating_meleeattacks_melee_attack_action_points'], values => { const pnd_act_pnt_chng = int(values.pending_action_point_change) + int(values.repeating_meleeattacks_melee_attack_action_points); console.log( 'load melee attacks' + '\n', 'pending_action_point_change: ' + pnd_act_pnt_chng ); setAttrs({pending_action_point_change: pnd_act_pnt_chng}); }); }); <fieldset class="repeating_meleeattacks"> <div class="expandable-section paleRedGradient"> <input class="expand-control" type="hidden" name="attr_melee_checkbox_expand" value="0"/> <div class="meleeAttacksTitleGrid"> <div class="mleapc blueBackground section"> <div class="fieldLabelCenter white blueBackground section">AP</div> <input class="field right manual24" name="attr_melee_attack_action_points" type="number" min='2'> </div> <div class="mleshw section"> <input type="checkbox" name="attr_melee_checkbox_expand" value="1" class="expandEntry expand-state" title="@{melee_checkbox_expand}" /><span title="Expand"></span> </div> <div class="mlelde blueBackground blueBorderTop1 section"> <button class="buttonStyleTop load" name="act_load_melee_attack" type="action" style="float:right;">Load</button> </div> </div> </div> </fieldset> <div class="pndap_ blueBackground section"> <input class="field manual19" name="attr_pending_action_point_change" type="number" value='0'> </div>
1599663261
GiGs
Pro
Sheet Author
API Scripter
You've stumbled across another roll20 glitch. I think I've seen this before, but I'd forgotten about it. Action Buttons cannot have underscores in their name. This doesnt work: name="act_load_melee_attack" But this does: name="act_load" Remember the act_ part isnt actually part of the name, its a prefix that gets snipped. The actual name is whataver comes after, and if it has an underscore in it, the sheet worker doesnt work. Testing this I noticed another (non-breaking) issue with your worker. This line: getAttrs(['repeating_meleeattacks_melee_attack_action_points'], values => { is followed by  int(values.pending_action_point_change) You dont have that attribute in the getAttrs lines, so it will always be zero.
1599663780
Andreas J.
Forum Champion
Sheet Author
Translator
GiGs said: You've stumbled across another roll20 glitch. I think I've seen this before, but I'd forgotten about it. Action Buttons cannot have underscores in their name. Huh, didn't remember that either. I recently updated the Button page for sheet creation, and now added a warning about this naming issue so we remember in the future: <a href="https://wiki.roll20.net/Button#Action_Button" rel="nofollow">https://wiki.roll20.net/Button#Action_Button</a>
Having made those changes, I'm afraid I'm still not seeing a log message.&nbsp; I think I may need to step away from this and come back to it later today.&nbsp; Sometimes that helps me to see something I didn't before. // load melee attacks on('clicked:repeating_meleeattacks:loadMeleeAttack', () =&gt; { console.log('test'); getAttrs(['pending_action_point_change', 'repeating_meleeattacks_melee_attack_action_points'], values =&gt; { console.log('test'); const pnd_act_pnt_chng = int(values.pending_action_point_change) + int(values.repeating_meleeattacks_melee_attack_action_points); console.log( 'load melee attacks' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ '\n', 'pending_action_point_change: ' + pnd_act_pnt_chng ); setAttrs({pending_action_point_change: pnd_act_pnt_chng}); }); }); &lt;fieldset class="repeating_meleeattacks"&gt; &lt;div class="expandable-section paleRedGradient"&gt; &lt;input class="expand-control" type="hidden" name="attr_melee_checkbox_expand" value="0"/&gt; &lt;div class="meleeAttacksTitleGrid"&gt; &lt;div class="mleapc blueBackground section"&gt; &lt;div class="fieldLabelCenter white blueBackground section"&gt;AP&lt;/div&gt; &lt;input class="field right manual24" name="attr_melee_attack_action_points" type="number" min='2'&gt; &lt;/div&gt; &lt;div class="mlelde blueBackground blueBorderTop1 section"&gt; &lt;button class="buttonStyleTop load" name="act_loadMeleeAttack" type="action" style="float:right;"&gt;Load&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;div class="pndap_ blueBackground section"&gt; &lt;input class="field manual19" name="attr_pending_action_point_change" type="number" value='0'&gt; &lt;/div&gt;
1599672461
Andreas J.
Forum Champion
Sheet Author
Translator
You probably want to replace that one "," with a "+" console.log('load melee attacks' + '\n' + 'pending_action_point_change: ' + pnd_act_pnt_chng); Having it on a single line might make the mistake/irregularity easier to spot.
1599693723

Edited 1599694723
OK.&nbsp; I have either deduced the answer or realized that you all have already given it to me, depending on your prospective. I fell victim to one of the classic blunders. The most famous is, as with repeating sections, never use underscores in action button names, as this will break them.&nbsp; B ut only slightly less well-known is this: Never use capital letters in repeating section names or action button names either, when they are in repeating sections!&nbsp; Ah ha ha ha ha ha ha ha!&nbsp; Ah ha ha ha ha ha ha ha!&nbsp; Ah ha ha ha . . . thud. I don't think this is specified in the sheet creation button page, but I could have missed it. My suspicion is that the names of any variables or action buttons or roll buttons will not work inside repeating sections, if they have either underscores or capital letters.&nbsp; I haven't tested this theory though.&nbsp; I can say that I had action buttons with underscores that were working outside of repeating sections.&nbsp; I would say though that best practice would be never to use underscores or capital letters in the names of action buttons, in case you ever want to put them in repeating sections. Thanks GiGs and Andreas for your patience. I'll add the working code below as soon as I'm done fiddling with it.
Here's the working code: // load melee attacks on('clicked:repeating_meleeattacks:loadmeleeattack', () =&gt; { getAttrs(['pending_action_point_change', 'repeating_meleeattacks_melee_attack_action_points'], values =&gt; { const pnd_act_pnt_chng = int(values.pending_action_point_change) - int(values.repeating_meleeattacks_melee_attack_action_points); console.log( 'load melee attacks' + '\n', 'pending_action_point_change: ' + pnd_act_pnt_chng ); setAttrs({pending_action_point_change: pnd_act_pnt_chng}); }); }); &lt;fieldset class="repeating_meleeattacks"&gt; &lt;div class="expandable-section paleRedGradient"&gt; &lt;input class="expand-control" type="hidden" name="attr_melee_checkbox_expand" value="0"/&gt; &lt;div class="meleeAttacksTitleGrid"&gt; &lt;div class="mleapc blueBackground section"&gt; &lt;div class="fieldLabelCenter white blueBackground section"&gt;AP&lt;/div&gt; &lt;input class="field right manual24" name="attr_melee_attack_action_points" type="number" min='2'&gt; &lt;/div&gt; &lt;div class="mlelde blueBackground blueBorderTop1 section"&gt; &lt;button class="buttonStyleTop load" name="act_loadmeleeattack" type="action" style="float:right;"&gt;Load&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;div class="pndap_ blueBackground section"&gt; &lt;input class="field manual19" name="attr_pending_action_point_change" type="number" value='0'&gt; &lt;/div&gt;
1599705457
GiGs
Pro
Sheet Author
API Scripter
Tim Z said: My suspicion is that the names of any variables or action buttons or roll buttons will not work inside repeating sections, if they have either underscores or capital letters.&nbsp;&nbsp; Capital letters will work in the button name. I posted code earlier that I tested and got working (when i changed the button name to "Load"). However, you must always use lower case letters on the event line (the (on'clicked) line ), even if the name has upper case letters in it. That said, it's good practice to use lower case letters all the time, for all attributes and button names. It means you wont run into these issues.