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

How do I reference a global attribute in a span in a repeating section?

I have a global attribute: <select name="attr_psionic_ability" value="15"> <option value="15">None</option> <option value="12">Minor</option> <option value="12">Major</option> <option value="10">Master</option> </select> In a repeating section, I want to reference it like: <span>Psionics vs. <span name="attr_psionic_ability"></span></span> However when I do this, the inner span is empty. I assume because it's trying to get that value in the context of the repeating row, and not globally? Is there a prefix or something I can put on it to tell it to use the global attribute?
1628310085
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You will need to create a second attribute that will pull the value from the global attribute. I would highly recommend doing this with a sheetworker.
1628313158
GiGs
Pro
Sheet Author
API Scripter
You have guessed the reason it's not showing correctly. The best way to get the value to show, is to use a sheet worker to update it. This should do it:      on ( 'change:psionic_ability' , ()  =>  {          const   section  =  'SECTION' ;          repeatingSectionIds ( `repeating_ ${ section } ` ,  idarray   =>  {              const   fieldnames  =  idarray . reduce (( rows , id )  =>  [... rows ,  `repeating_ ${ section } _ ${ id } _psionic_ability` ],  '' );              getAttrs ([ 'psionic_ability' , ... fieldnames ],  v   =>  {                  const   output  = {};                  idarray . forEach ( id   =>  {                      output [ `repeating_ ${ section } _ ${ id } _psionic_ability` ] =  v . psionic_ability ;                 });                  setAttrs ( output );             });         });     });    Just change one thing: the section at the start needs to be set to your repeating section name, the bit after repeating_. If you have multiple external attributes you want to show in a repeating section, here's a worker for that. Just change the section variable at the start, like above, and add the attributes in the array below it. You only have to change those first 2 lines.      const   section  =  `SECTION` ;      const   repeating_stats  = [ 'psionic_ability' ];      const   changes  =  repeating_stats . reduce (( str ,  stat )  =>   ` ${ str }  change: ${ stat . toLowerCase () } ` ,  'sheet:opened' );      on ( changes , ()  =>  {          getSectionIDs ( `repeating_ ${ section } ` ,  idarray   =>  {              const   fieldnames  =  idarray . reduce (( rows , id )  =>  [... rows , ... repeating_stats . map ( stat   =>   `repeating_ ${ section } _ ${ id } _ ${ stat } ` )], []);              getAttrs ([... repeating_stats , ... fieldnames ],  v   =>  {                  const   output  = {};                  idarray . forEach ( id   =>  {                      repeating_stats . forEach ( stat   =>  {                          output [ `repeating_ ${ section } _ ${ id } _ ${ stat } ` ] =  v [ stat ];                     });                 });                  setAttrs ( output );             });         });     });