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 .
×

[Help] Accessing "normal" attributes inside a repeating section.

1610839747

Edited 1610839966
So from reading the docs I understand that I can't have a "normal" attribute with the same name as an attribute in a repeating section. Does that mean I can't read "normal" attributes in a repeating section. For example, I have  attr_shooting  as a normal attribute. I would like to then have a repeating section for listing weapons and display that value and it doesn't seem to work. When I try (as a simplified example): <fieldset class="repeating_weapons">   <span name="attr_shooting"> </fieldset> The span is empty. Does anyone know if what I'm trying to do is possible, or if there's a different approach I should be trying?
1610852097
GiGs
Pro
Sheet Author
API Scripter
For your first paragraph: in fact you can have attributes name the same inside a repeating section as outside. It's just a bad idea, for reasons that are a bit technical. So avoiding doing that is a good idea. The problem your having here is when you put an attribute inside a repeating section, its name changes . A repeating section is like a blueprint, which roll20 uses to build the contents in away that works when the sheet is loaded. Every atttribute in a repeating section gets a name that is made of three parts:     the repeating section name     a unique ID that identifies which row that attribute is on     and the thing you have set p as the attribute name. So take this code: <fieldset class="repeating_weapons">   <span name="attr_shooting"> </fieldset> when that sheet gets loaded, the repeating section iwll have 0, 1, 2, or more rows. Each of those rows will have a shooting attribute on it. For roll20 to identify which shooting attribute is actually being used, it constructs a longer attribute name (with the three parts above) that will look like repeating_weapons_-GRTUWEN67385_shooting This means when you take code for an attribute from outside of a repeating section and put it in the repeating section, you are creating a completely new attribute (possibly many new attributes - one for each row, remember), that has no connetcion to the original code. They are different attributes. If you want to transfer that attribute value to the fieldset, you need to use a sheet worker. Here's one that should do the trick: on ( 'change:shooting sheet:opened' , ( e )  =>  {      getSectionIDs ( 'repeating_weapons' ,  rowids   =>  {          const   output  = {};          rowids . forEach ( id   =>   output [ `repeating_weapons_ ${ id } _shooting` ] =  e . newValue );          setAttrs ( output );     }); }); This will take whatever value the shooting attribute has outside the repeating section, and copy it to that attribute on all the rows of the repeating section, and keep it updated when the value changes. Add this to your sheets script block. If you dont have one, create one, and put that inside it. I'd recommend changing the attribute in the repeating section to something like 'shootingcopy' which would change the worker above to: on ( 'change:shooting sheet:opened' , ( e )  =>  {      getSectionIDs ( 'repeating_weapons' ,  rowids   =>  {          const   output  = {};          rowids . forEach ( id   =>   output [ `repeating_weapons_ ${ id } _shootingcopy` ] =  e . newValue );          setAttrs ( output );     }); });
Thank you so much, this is extremely helpful. That is exactly the information I was looking for.