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

Need Help Referencing an Nested Input Value

1682285123

Edited 1682285196
Hello Roll20 Community, I am working on creating a custom character sheet for a friend of mine and they are wanting to have a section where players can create their own global damages that get added to all of their rolls. I am having trouble finding a way to reference an input that is deeply nested within multiple elements so the whole rest of the sheet can reference it.
1682295246
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Can you explain what you mean by nested? Do you mean a repeating attribute?
Yes, my apologies. The input I want to call from is from a repeating fieldset. So players can make as many as they need. But the div the input is in is a part of a fieldset that is about 6 layers deep in divs. This is making it hard to reference for other rolls outside of that div. Does that make any sense?
For reference, this is an example of what I'd like to make work: <div class="wholesheet">    <div class="section2">       <div class="features">          <fieldset class="repeating_features">             <div class="description">                <input class="globalDamage" name="attr_globalDamage">             </div>          </fieldset>       </div>       <div class="equipment">          <button type="roll" value="1d20 + @{globalDamage}">       </div>    </div> </div> <div class="magicTab">    <button type="roll" value="1d20 + @{globalDamage}"> </div>
1682304313
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Ah, ok. You're misunderstanding how Roll20 character sheet code works. The depth of the divs has no bearing on how you access an attribute value. The only thing that changes how attributes are accessed is having them in a repeating section. To access those you need to reference the specific row id of the repeating row. There is no way to do this with just macro syntax. You need sheetworkers to do one of: Have a sheetworker that watches for changes to the repeating_features_globaldamage attribute and updates an attribute (true_global_damage) with the total of all global damage modifiers Use custom roll parsing to do your rolls instead of basic roll buttons and then have the total global damage mod calculated at roll time
Oh ok, excellent. I'll look into those and give them a shot, thanks! 
1682730040

Edited 1682730096
Thanks for your help! The sheetworkers word like a charm! But now I have a new question. First, here is the code I have now & it works well if you only have 1 global damage set. on("change:repeating_globals:globaldmg sheet:opened", function() { getAttrs (["repeating_globals_globaldmg"], function(values) { let gd = parseInt(values.repeating_globals_globaldmg)||0; setAttrs ({"global": gd}); }); }); What do I have to add to the code for it to add all of the global damages together? Is that possible?
1682732556
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
that is, you need to use the getSectionIDs function. See the wiki page on summing repeating sections for a ready made code snippet.
That's perfect. Thanks!