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

Pull values from repeating section

My system uses maneuvers, which are based off of skills. I have a repeating skill section where characters can add new skills, and I am creating a repeating section for maneuvers. Ideally, I would like to have a dropdown list where the player can select the related skill for the maneuver from a list of all of their existing skills. Is there a way to do something like this?
1611428323
GiGs
Pro
Sheet Author
API Scripter
Simple answer: no. You cant have a dynamically created list or dropdown. If you have a fixed list of possible skills, then you can create a dropdown with that list, and put it inside the repeating section. But you cant dynamically filter this list based on which skills the character has or does not have.
Didn't think so. Still, had to ask.
1611462971
GiGs
Pro
Sheet Author
API Scripter
It would be a very nice feature to have.
Is there any way to search repeating sections and get values from them at all? I have another, unrelated idea I'm working on that would require doing that.
1611552146
GiGs
Pro
Sheet Author
API Scripter
You'll have to be specific about what you're trying to do. That's a bit too vague and all I can say in response is "maybe".
I have that health section that you helped me with that awesome sheet worker. I am including a wounds section on my sheet where. each wound could be detailed out. In my ideal version, it would be a repeating section where you could add wounds. Each time a wound was added or its severity changed, it would read the severity of each wound in the section and then, starting from the first health box in that category or higher, it would find the first unchecked health box and check it. 
1611581276
GiGs
Pro
Sheet Author
API Scripter
Yes thats definitely something you can do. You have to be careful with the logic here. For instance, lets so you add a Severe wound. This clicks the first severe wound checkbox. Then that wound starts healing and becomes a Light wound. Now you have to add a Light wound to the health track, but you also have to remove a Severe wound from it. Then: if you manually click a box on the health track, should it add a wound of that severity to the Wounds repeating section? And when doing so, how do you make sure that this doesnt set an infinite loop chain reaction: You click the wound track to add a Light wound A worker detects this and adds a Light Wound to the repeating section The repeating section worker detects a light wound is added and so adds another light wound to the health track That worker detects that and so adds another light wound to the repeating section and that triggers.. and so on infinitely  It's possible to handle this, but you need to be clear about what you want to happen.
As far as the logic, my thinking was kinda brute force. I thought I could clear all the check boxes and then search all the wounds in the repeating section and have each check the appropriate health box.
1611583930
GiGs
Pro
Sheet Author
API Scripter
Remember that nay change to the health track is going to trigger any sheet workers watching it, and if you have a sheet worker that adds wounds to the repeating section, that iwll create the infinite loop I mentioned before, unless you specifically code to vaoid it. When someone clicks a wound on the wound track, should it add a wound to the repeating section? The overall problem isnt that tricky if its one way: either Players click the health track, and wounds are created in the repeating section that match the track Players create, change, or remove wounds in the repeating section, and the health track is updated to show the wounds It gets tricky when players can do both. Then you have to be careful that one doesnt trigger the other. To be clear its possible to handle this, but it is best solved with a single sheet worker that handles both the health track and the repeating section. can you post the html for the repeating section, and the html and sheet worker for the health track (since I didnt save them).
1611584233

Edited 1611584312
I'm using the following to show the severity of each wound: <table class="wound-container">     <tr>         <td rowspan="2" style="width:64px;vertical-align:center;">             <input type="hidden" name="attr_severity_1" class="severity" value="0" />             <span class="none">None</span>             <span class="trivial">Trivial</span>             <span class="light">Light</span>             <span class="moderate">Moderate</span>             <span class="severe">Severe</span>             <span class="fatal">Fatal</span>         </td>         <td>             <button type="action" name="act_severity_1_cycleup" class="severity-button up"></button>         </td>     </tr>     <tr>         <td>             <button type="action" name="act_severity_1_cycledown" class="severity-button down"></button>         </td>     </tr> </table> <script type="text/worker">   on(`clicked:severity_1_cycleup`, () => {       // Check the current value of the hidden attribute.     getAttrs(["severity_1"], (v) => {       const severityValue = parseInt(v["severity_1"]) || 0;       var newVal=severityValue + 1       if(newVal>5){           newVal=5       }       // Increment the attribute value by 1, or cycle back to 0 if the incremented value is equal to 4.       setAttrs({         "severity_1": newVal       });     });   });   on(`clicked:severity_1_cycledown`, () => {       // Check the current value of the hidden attribute.     getAttrs(["severity_1"], (v) => {       const severityValue = parseInt(v["severity_1"]) || 0;       var newVal=severityValue - 1       if(newVal<1){           newVal=0       }       // Increment the attribute value by 1, or cycle back to 0 if the incremented value is equal to 4.       setAttrs({         "severity_1": newVal       });     });   }); </script> with CSS: button[type="action"].sheet-severity-button:focus{     outline:none; } .sheet-up{     background:none;     padding:0px;     font-size:8px;     border-left: 4px solid transparent;     border-right: 4px solid transparent;     border-bottom: 8px solid black;     border-top: 0px solid transparent;     display: inline-block;     height:2px; } .sheet-down{     background:none;     margin-top:2px;     padding:0px;     font-size:8px;     border-left: 4px solid transparent;     border-right: 4px solid transparent;     border-bottom: 0px solid transparent;     border-top: 8px solid black;     display: inline-block;     height:2px; } .sheet-none, .sheet-trivial, .sheet-light, .sheet-moderate, .sheet-severe, .sheet-fatal{     display:none;     width:64px;     margin-top:8px; } input[type="hidden"].sheet-severity[value="0"] ~ .sheet-none, input[type="hidden"].sheet-severity[value="1"] ~ .sheet-trivial, input[type="hidden"].sheet-severity[value="2"] ~ .sheet-light, input[type="hidden"].sheet-severity[value="3"] ~ .sheet-moderate, input[type="hidden"].sheet-severity[value="4"] ~ .sheet-severe, input[type="hidden"].sheet-severity[value="5"] ~ .sheet-fatal{     display:block; } The idea would be to update all the health boxes whenever  severity_1_cycleup or  severity_1_cycledown was clicked, based on the value of  severity_1. actually, logically it would make more sense to update on "change: severity_1"
1611585421
GiGs
Pro
Sheet Author
API Scripter
Randall S. said: The idea would be to update all the health boxes whenever  severity_1_cycleup or  severity_1_cycledown was clicked, based on the value of  severity_1. actually, logically it would make more sense to update on "change: severity_1" I think it would be best to handle it in the click events, and not have a change:severity_1  event.  Why severity_1 , and not just severity ?
I was originally going to have several rows for wounds that would have been severity_1, severity_2, etc., but then I thought there might be a way to do it with a repeating section that would be cleaner.
1611589188
GiGs
Pro
Sheet Author
API Scripter
That makes sese. A repeating section for this would be pretty good- it handles any number of wounds. That said, your health track suggests there's a fairly small maximum number of wounds (4 trivial, 3 light, etc). You could easily have them all hardcoded, and use CSS to hide them all, and just show them when their matching healthbbar button is checked.
There are a maximum of 12 wounds, so I was going to list them. Hiding the unchecked ones might be the way to go.
If a character has all the boxes checked for a category and takes another wound, it moves up one category. So, if a character has already taken 3 light wounds, and they get hit for another light wound, it becomes a moderate wound. for purposes of healing and such, it is still a light wound, but it would check off a moderate wound box. I thought it might be neat (though not absolutely necessary) to automate that by having it find the first unchecked box of that value or higher.
1611592573

Edited 1611592704
GiGs
Pro
Sheet Author
API Scripter
That sounds like a good reason to keep it as a repeating section. OR if you have a fixed set of boxes, have a way to display a variable wound level for each of the 12 wounds. If I remember correctly though, there's no way to handle what you describe from the health track: if you click a light wound when you already have 3 marked, it just unchecks that light box, it doesnt add another. So you might need to abandon the clickability of the health track, and handle wounds being added purely through the repeating section (which then updates the health track with the effective  wounds.
Yeah, it makes more sense to do it from the repeating section than to click on the bar. I was already planning to disable the buttons in the bar and put an enabled copy in the list section. If it was possible to do it from a repeating section, then I would not have the copy, and the buttons would be purely for display. The only problem is that, to make it work, I would have to clear all the checkboxes, and then be able to search the repeating section and find the value of each wound and check an appropriate box.
In psuedo code it would be something like this: for each number(1-12){ health${number}_flag=0 } for each wound(repeating wounds){ const woundChecked=0 for each healthBox(severity - 12){ if(repeating-wound-severity>0){ if(health[healthbox]_flag=0 & woundChecked=0){ health[healthbox]_flag=1 woundChecked=1 } } } } }  Then check the value for wounded-mod as in the previous script.
1611596603
GiGs
Pro
Sheet Author
API Scripter
Randall S. said: Yeah, it makes more sense to do it from the repeating section than to click on the bar. I was already planning to disable the buttons in the bar and put an enabled copy in the list section. That does make things easier. what do you mean by enabled copy here? enabled copy of what?  If it was possible to do it from a repeating section, then I would not have the copy, and the buttons would be purely for display. The only problem is that, to make it work, I would have to clear all the checkboxes, and then be able to search the repeating section and find the value of each wound and check an appropriate box. You're pseudo code is a good place to start. But you dont need to initialise them all to zero. You'll have the values set with each wound in the repeating section. A sheet worker can tell you which item was clicked, and what its previous and new values were, using the eventInfo object. So if you are changing a wound from medium to light (for healing, say), the sheet worker can check the get the values of each current wound, and know which one was medium and is now light, so its possible to calculate everything you need to. You can examine the entire repeating section (all the wounds within it) using the getSectionIDs function. So your code needs to handle four cases: creating a brand new wound stepping up a wound stepping down a wound removing a wound completely And it needs to update the health track hidden attributes (which itself will recalculate the wound penalty). This part could have some tricky logic, since it means calculating wounds that are different from those in the repeating section (a 4th light wound that become a moderate wound, especially if you already have some moderate wounds, etc). What is the html for those health track inputs again?
A light wound that becomes a moderate wound would still have the same penalty as a normal moderate wound. It would just be a light wound so that, if another light wound was healed, making room for it, it would fall down into that category, and no longer have the higher penalty.  It would also be easier to heal than a normal moderate wound. the HTMl for the health bar was:             <div class="health-bar">                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health1_flag" value="0" />                   <button type="action" name="act_health1" class="health left-cap">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health2_flag" value="0"/>                   <button type="action" name="act_health2" class="health">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health3_flag" value="0" />                   <button type="action" name="act_health3" class="health">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health4_flag" value="0" />                   <button type="action" name="act_health4" class="health bar-divider">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health5_flag" value="0" />                   <button type="action" name="act_health5" class="health">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health6_flag" value="0" />                   <button type="action" name="act_health6" class="health">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health7_flag" value="0" />                   <button type="action" name="act_health7" class="health bar-divider">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health8_flag" value="0" />                   <button type="action" name="act_health8" class="health">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health9_flag" value="0" />                   <button type="action" name="act_health9" class="health bar-divider">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health10_flag" value="0" />                   <button type="action" name="act_health10" class="health">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health11_flag" value="0" />                   <button type="action" name="act_health11" class="health bar-divider">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health12_flag" value="0" />                   <button type="action" name="act_health12" class="health right-cap">k                     <span class="chequed">k</span>                   </button>                 </div>                 <input type="hidden" name="attr_wounded-mod" value="0" readonly>                 <input type="hidden" name="attr_wound-penalty-1" value="-1*(@{wounded-mod}-3+@{will})" disabled>                 <input type="number" class="wound-mod" name="attr_wound-penalty-2" value="((@{wound-penalty-1}+abs(@{wound-penalty-1}))/-2)" disabled>             </div>             <div class="health-bar">                 <label style="width:96px;text-align:center;padding:0px;font-weight:normal;font-size:10px;border-right: solid 1px;">Trivial</label>                 <label style="width:72px;text-align:center;padding:0px;font-weight:normal;font-size:10px;border-right: solid 1px;">Light</label>                 <label style="width:48px;text-align:center;padding:0px;font-weight:normal;font-size:10px;border-right: solid 1px;">Moderate</label>                 <label style="width:48px;text-align:center;padding:0px;font-weight:normal;font-size:10px;border-right: solid 1px;">Severe</label>                 <label style="width:32px;text-align:center;padding:0px;font-weight:normal;font-size:10px;">Fatal</label>             </div>             </div>
i have another thing this would be useful for. I am including a couple of checkboxes next to each wound to represent conditions such as bleeding or poisoned. I would love to be able to search the section and find if any of those are checked, so I can turn on an indicator at the top of the sheet to that the character is bleeding if they have at least one bleeding wound.
1611646924
GiGs
Pro
Sheet Author
API Scripter
When you ask for something, you need to give the relevant attribute names, and preferably their html so we can see their structure. This is possible (its not too hard), but knowing which attributes need to be checked and what exactly needs to be saved is necessary to know.
Sorry for being vague. What I have currently is a row where it lists the severity of the wound in a span (named severity) with two buttons to change the value up or down, has a text box for a description of the wound (named wound-desc), a cycling checkbox to record whether the wound is normal(value=0), bleeding(value=1), or bandaged(value=2) named bleed, and a checkbox to record whether the wound is poison (named poison) which has a value of 0 for normal and 1 for poisoned. I am currently using them in rows where each one has a _1, or _2, etc. appended to the name for the corresponding row. I want to put them in a repeating section and have each check the appropriate box on my wound track. Ideally, I would want to have an input named "bleeding status" that would display a value of "Bleeding" if one or more of the rows has a bleed checkbox with a value of 1. Similarly, I want to have an input named "poison-status" that would indicate if one or more poison checkboxes were ticked.  The current HTML for a row is this:         <div class="health-container">           <div class="wound-row">             <table class="wound-container">                 <tr style="padding:0px;">                     <td rowspan="2" style="width:72px;padding-top:6px;">                         <input type="hidden" name="attr_severity_1" class="severity" value="0" />                         <span class="none">None</span>                         <span class="trivial">♥ Trivial</span>                         <span class="light">♥ Light</span>                         <span class="moderate">♥ Moderate</span>                         <span class="severe">♥ Severe</span>                         <span class="fatal">♥ Fatal</span>                     </td>                     <td style="padding:0px;">                         <button type="action" name="act_severity_1_cycleup" class="severity-button up">▲</button>                     </td>                 </tr>                 <tr style="padding:0px;">                     <td style="padding:0px;">                         <button type="action" name="act_severity_1_cycledown" class="severity-button down">▼</button>                     </td>                 </tr>             </table>             <input type="text" name="attr_trivial-desc" class="wound-info"/>             <div class="bleed-container">               <input type="hidden" class="bleed" name="attr_bleed1_flag" />               <button type="action" name="act_bleed1" class="bleed">                 <span class="checked tear" title="Bleeding">&</span>               </button>             <div class="poison-container">                 <input type="hidden" class="poison" name="attr_poison_flag" />                 <button type="action" name="act_poison" class="poison" title="Poisoned">                     <span class="poison-checked">l</span>                 </button>             </div>             </div>           </div>         </div> Which I would wrap inside of <fieldset class="repeating_wounds"> </fieldset> And the HTML for the wound track is:             <div class="health-bar">                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health1_flag" value="0" />                   <button type="action" name="act_health1" class="health left-cap">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health2_flag" value="0"/>                   <button type="action" name="act_health2" class="health">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health3_flag" value="0" />                   <button type="action" name="act_health3" class="health">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health4_flag" value="0" />                   <button type="action" name="act_health4" class="health bar-divider">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health5_flag" value="0" />                   <button type="action" name="act_health5" class="health">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health6_flag" value="0" />                   <button type="action" name="act_health6" class="health">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health7_flag" value="0" />                   <button type="action" name="act_health7" class="health bar-divider">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health8_flag" value="0" />                   <button type="action" name="act_health8" class="health">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health9_flag" value="0" />                   <button type="action" name="act_health9" class="health bar-divider">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health10_flag" value="0" />                   <button type="action" name="act_health10" class="health">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health11_flag" value="0" />                   <button type="action" name="act_health11" class="health bar-divider">k                     <span class="chequed">k</span>                   </button>                 </div>                 <div class="health-container">                   <input type="hidden" class="health" name="attr_health12_flag" value="0" />                   <button type="action" name="act_health12" class="health right-cap">k                     <span class="chequed">k</span>                   </button>                 </div>                 <input type="hidden" name="attr_wounded-mod" value="0" readonly>                 <input type="hidden" name="attr_wound-penalty-1" value="-1*(@{wounded-mod}-3+@{will})" disabled>                 <input type="number" class="wound-mod" name="attr_wound-penalty-2" value="((@{wound-penalty-1}+abs(@{wound-penalty-1}))/-2)" disabled>             </div>             <div class="health-bar">                 <label style="width:96px;text-align:center;padding:0px;font-weight:normal;font-size:10px;border-right: solid 1px;">Trivial</label>                 <label style="width:72px;text-align:center;padding:0px;font-weight:normal;font-size:10px;border-right: solid 1px;">Light</label>                 <label style="width:48px;text-align:center;padding:0px;font-weight:normal;font-size:10px;border-right: solid 1px;">Moderate</label>                 <label style="width:48px;text-align:center;padding:0px;font-weight:normal;font-size:10px;border-right: solid 1px;">Severe</label>                 <label style="width:32px;text-align:center;padding:0px;font-weight:normal;font-size:10px;">Fatal</label>             </div>             </div>
I am struggling with this whole repeating sections thing. The following is one of the sheet workers for one of my repeating section buttons. It worked fine outside of a repeating section, but when I pasted it into a repeating section and changed the names to include the "repeating_wounds" it did not work. What am I doing wrong. <script type="text/worker">   on(`clicked:repeating_wounds:severity-cycleup`, () => {       // Check the current value of the hidden attribute.     getAttrs(["repeating_wounds_severity"], (v) => {       const severityValue = parseInt(v["repeating_wounds_severity"]) || 0;       var newVal=severityValue + 1       if(newVal>5){           newVal=5       }       // Increment the attribute value by 1, or cycle back to 0 if the incremented value is equal to 4.       setAttrs({         "repeating_wounds_severity": newVal       });     });   }); </script>