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

Use a drop down to select a value from a repeating list.

In the sheet I am developing, a player buys skill ranks in a spell list.  This happens on the skills page. On a separate page (the spells lists page), there are the spells lists, that contain all the spells within that list.  (I know that the page it is on doesn't really matter, but I am illustrating the layout, I hope)  Other modifiers that apply at the time of casting the spell, that modify the skill ranks you bought are applied here. You also make your casting rolls here.  The spell lists are in a repeating section, and the spell skills are in a repeating section. The design I have in mind is on the spells page you would select the skill you bought the ranks in.  It should be limited to only certain skills, and ideally no skill can be selected more than once. Is this possible? If this is not possible, I will probably just have them enter the total skill bonus and be done with it.  But it would be awesome if it could be worked out!
1632424769
GiGs
Pro
Sheet Author
API Scripter
If the skills list is fixed, it would be better to use a non-repeating list, and CSS to hide those the character does not possess. (The traveller sheets show a great way to manage this.) This makes getting any values based on the skill very easy. But it is possible possible to get the skill name from the repeating section containing the skill list and other values, using the getSectionIDs function. I cant tell what attributes you'd need from the skill repeating section (their names) or whether to are triggering a roll using an action button or a roll button, so I cant give full code. There's multiple ways the code could be written. This is the procude I'd follow: Have a sheet worker that is triggered whenever one of these two things happen: the skill value in the skill list changes, and the skill name in the spell list is changed. You need both those events to make sure the bonus is kept properly updated at all times. (Players might change the skill associated with a spell, and their skill value might change.) Also, the skill bonus must be calculated by sheet worker, or be a single number value - it cant be an autocalc value. Its best of the skill name is chosen from a fixed list (like a select dropdown) - if players enter it manually, there's a very good chance of user error (getting the names to match in both repeating sections is essential, and players will do typoes). With these in place, the worker would do this: it scans the skill list, grabs the value for the matching skill, and copies it to an attribute on that spell section. This attribute might be visible (if you want to display the skill bonus) or hidden - but for this method, it must exist. Then when you make a roll, your roll grabs the skill value along with any other values needed in the spell section, and voila, all is well. To make this code, I'd need answer all of the questions following: What are the names of the two repeating sections? What is the name of these two attributes in skills section you want to grab:     The attribute holding the skill name     the attribute holding the bonus value you want to grb for the spell. In the spell section, what is the name of these attributes:     the name of the attribute holding the skill associated with the spell        the name of the attribute you'd like to srore the copied skill bonus in. It's a bit more tricky than most repeating section workers, because you need to nest one getSectionIDs inside the other, but it's not too complex.
GiGs said: What are the names of the two repeating sections? There are many, but the one I am testing on is Source: <fieldset class="repeating_baselistskill"> Destination: <fieldset class="repeating_baselist"> What is the name of these two attributes in skills section you want to grab: Ideally we can get: the name:    name="attr_baselistskillname"  copied to name="attr_baselistname"  (or used in the dropdown?  see below) ranks bought: name="attr_baselistskillranks" copied to name="attr_baselistranks" total skill bonus: name="attr_baselistskilltotal" copied to name="attr_baselisttotal" The attribute holding the skill name see above The attribute holding the bonus value you want to grab for the spell. see above In the spell section, what is the name of these attributes: see above The name of the attribute holding the skill associated with the spell  I am not sure I understand this, but if I do, I have not set that up.  I just figured they would select the name from the drop down so that would be: name="attr_baselistskillname" The name of the attribute you'd like to store the copied skill bonus in. see above
1632439954

Edited 1632482365
GiGs
Pro
Sheet Author
API Scripter
I am not sure I understand this, but if I do, I have not set that up.  I just figured they would select the name from the drop down so that would be: You'll need to grab the numerical value from the skill list section, and copy that to to the spell list section. Just to avoid confusion: how do you plan to use the value gained? What does the code for your spell button  look like? Later Edit: it looks like you are copying both the total bonus and the skill ranks from one section to the other. If so, that answers this question. Also just for reference, the attr_ part isnt part of the attribute name. It's an indicator to roll20 saying, "this is an attribute". So with say attr_strength , when roll20 looks up the value of that attribute, it splits into two parts, attr , and strength . This says to rolls, "this is an attribute named strength" and so it looks in the table of attributes, and grabs the value for the one called strength. There are other flags like attr_ (e.g. act_, roll_) which are used internally, but are never used by us users (not even sheet designers or script writers). When we want to refer to an attribute, we just use the name strength .
1632483935

Edited 1632629019
GiGs
Pro
Sheet Author
API Scripter
Here's a sheet worker you can try. A worker as complex as this might not work on first attempt - i may need  a copy of the sheet to test. But if it works first time, yay! Note there's a variable at the start, const spellstats , that contains the various attribute names. This is there in case you change your attribute names - you just have to change them in this one place. I did this because your attribute names look a bit clunky and you might want to change them for increased clarity. Like one repeating section might be called repeating_skills, and the other repeating_spells, and the attributes within them similarly made a bit more distinct and clear. But anyway, whether you change them or not, here's the worker to test. /*     each spell must have a skill assigned. if the skill doesnt match a skill in the skillsection,           bonus and ranks will both be set to 0.     If there is no name assigned at all, then no ranks or bonus will be calculated.     if the first section contains two or more identical skill names (an error),           the function below will assume the LAST one is correct. */ const   spellstats  = {      skillsection :   'repeating_baselistskill' ,      spellsection :   'repeating_baselist' ,      skills_name :   'baselistskillname' ,      skills_ranks :   'baselistskillranks' ,      skills_bonus :   'baselistskilltotal' ,      spells_name :   'baselistname' ,      spells_ranks :   'baselistranks' ,      spells_bonus :   'baselisttotal' }; on ( `change: ${ spellstats . skillsection } : ${ spellstats . skills_name }  change: ${ spellstats . skillsection } : ${ spellstats . skills_bonus }  change: ${ spellstats . spellsection } : ${ spellstats . spells_name } ` ,()  =>  {      getSectionIDs ( spellstats . skillsection ,  idSkills   =>  {          getSectionIDs ( spellstats . spellsection ,  idSpells   =>  {              const   getRepeatingName  = ( section ,  id ,  field )  =>   ` ${ section } _ ${ id } _ ${ field } ` ;              const   skillsnames  =  idSkills . reduce (( s ,  row )  =>  [... s ,                   getRepeatingName ( spellstats . skillsection ,  row ,  spellstats . skills_name ),                  getRepeatingName ( spellstats . skillsection ,  row ,  spellstats . skills_ranks ),                   getRepeatingName ( spellstats . skillsection ,  row ,  spellstats . skills_bonus )], []);              const   spellsnames  =  idSpells . reduce (( s ,  row )  =>  [... s ,  getRepeatingName ( spellstats . spellsection ,  row ,  spellstats . spells_name ),], []);              // you dont need to READ the ranks and bonuses in the spells section, just write them, so dont need to grab them here.              getAttrs ([... skillsnames , ... spellsnames ],  v   =>  {                  const   output  = {};                                   // build an object with a key = skill, and values = ranks and total.                  const   skillsobject  =  idSkills . reduce (( a ,  row )  =>  ({... a ,                       [ v [ getRepeatingName ( spellstats . skillsection ,  row ,  spellstats . skills_name )]]:  {                          ranks :   v [ getRepeatingName ( spellstats . skillsection ,  row ,  spellstats . skills_ranks )],                          bonus :   v [ getRepeatingName ( spellstats . skillsection ,  row ,  spellstats . skills_bonus )]                     }                 }), {});                  //iterate through items in spells, and for each one get the ranks aand bonus from above object.                  idSpells . forEach ( spellrow   =>  {                      const   skillname  =  v [ getRepeatingName ( spellstats . spellsection ,  spellrow ,  spellstats . spells_name )] ||  undefined ;                      if ( skillsobject . hasOwnProperty ( skillname )) {                          output [ getRepeatingName ( spellstats . spellsection ,  spellrow ,  spellstats . spells_ranks )] =                                   skillsobject [ skillname ]. ranks ;                          output [ getRepeatingName ( spellstats . spellsection ,  spellrow ,  spellstats . spells_bonus )] =                               skillsobject [ skillname ]. bonus ;                     }  else  {                          output [ getRepeatingName ( spellstats . spellsection ,  spellrow ,  spellstats . spells_ranks )] =  0 ;                          output [ getRepeatingName ( spellstats . spellsection ,  spellrow ,  spellstats . spells_bonus )] =  0 ;                     }                 });                  if  ( output )  setAttrs ( output );             });         });     }); });
Thanks - I will give it a shot this weekend.
1632544238
GiGs
Pro
Sheet Author
API Scripter
I noticed a couple of critical errors in the worker and have updated the code and tested it now, it works for me.
1632628929
GiGs
Pro
Sheet Author
API Scripter
I just updated the code again. The previous code worked fine, but there wa a function that was more complex and convoluted than it needed to be, and it was nagging at me that I was forgetting a better way to do it. So if you've tried the previous code, that's fine - it was perfectly workable (based on my testing) but the updated code is a bit better.
Well - I got started into it, and I found errors in how I was using repeating skills, so I ended up spending my time fixing that.  It seems to be right now, so I will push that up, fix my HTML code builder, and then get stuck into this.