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

Referencing an attr from within a repeating section

I have an attr outside a repeating section and I need to reference it within a repeating section, like this: <input type="number" name="attr_will" /> <fieldset class="repeating_gear"> <input type="number" name="attr_will" /> </fieldset> But they act completely independently and the Wiki says what I'm after isn't possible. Is there a workaround? Could a sheetworker do this?
1628582937

Edited 1628583029
GiGs
Pro
Sheet Author
API Scripter
The way to do this is to create a copy of the attribute's value in a new attribute within the repeating section, using a sheet worker. Say, create an attribute called will_copy in the repeating section, and then have an sheet worker like this. on('change:will', () => {     getAttrs(['will'], v => {         getSectionIDs('repeating_gear', ids => {             const output = {};             ids.forEach(id => output[`repeating_gear_${id}_will_copy`] = v.will);             setAttrs(output);         });     }); }); If you have a bunch of attributes you want to copy in repeating sections, thats not very efficient. In that case, fololow these steps: Make sure the copies of the attributes in each section have the same name, with _copy appended to them Create an object variable in your sheet worker script block like this: const   repeatingCopies  = {    gear :  [ 'will' ,  'strength' ],    powers :  [ 'will' ,  'charisma' ], }; You have the repeating section name (without the repeating_ part) on the left, and an array of the attributes you want copied into that section on the right. So whenever you want to add a copy of an attribute to a repeating section, just update the structure above, and the sheet worker side will be handled automatically. This is the only section of the code you need to adjust. Finally copy this code and place it beneath the above object. You do not need to modify this. Object . keys ( repeatingCopies ). forEach ( section   =>  {    repeatingCopies [ section ]. forEach ( copy   =>  {      on ( `change: ${ copy } ` , ()  =>  {        getAttrs ([ copy ],  v   =>  {          getSectionIDs ( `repeating_ ${ section } ` ,  ids   =>  {            const   output  = {};            ids . forEach ( id   =>   output [ `repeating_ ${ section } _ ${ id } _ ${ copy } _copy` ] =  v [ copy ]);            setAttrs ( output );         });       });     });   }); }); This code could be made a lot more efficient, but honestly isn't likely to affect the sheet performance. It'll ensure that whenever an attribute that has a copy inside a repeating section is changed, all its copies change.
1628585379
Andreas J.
Forum Champion
Sheet Author
Translator
Seen lots of Rep Section questions lately, added links to documentation on some of GiGs examples: <a href="https://wiki.roll20.net/Repeating_Sections#Tips" rel="nofollow">https://wiki.roll20.net/Repeating_Sections#Tips</a>
That's amazing. Perfect solution working perfectly. Many thanks!
1628600747
GiGs
Pro
Sheet Author
API Scripter
Yay! you're welcome :)