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

Help with fieldsets

I have a injury dropdown I want to make into a fieldset because I want it to be possible to have multiple injurys.  Its currently set to automatically effect rolls using a script worker.  When its not a fieldset it works perfectly.  I just need help making it so the code that just checks if a dropdown is yes or no and still sends it to the script worker.  The fieldset is currently named repeating_injurys, and the script is below. <script type="text/worker"> // Define the values each injury contributes to different stats const injuryValues = {     winded: { physicality: -2, endurance: 0, mentality: 0, intellect: 0, observation: 0, charm: 0 },     dizzy: { physicality: 0, endurance: 0, mentality: 0, intellect: 0, observation: -3, charm: 0 },     groggy: { physicality: 0, endurance: -2, mentality: -2, intellect: 0, observation: 0, charm: 0 },     disoriented: { physicality: 0, endurance: 0, mentality: 0, intellect: -4, observation: -4, charm: 0 },     nauseous: { physicality: -2, endurance: 0, mentality: 0, intellect: 0, observation: 0, charm: 0 },     blurred_vision: { physicality: 0, endurance: 0, mentality: 0, intellect: 0, observation: -3, charm: 0 },     ringing_ears: { physicality: 0, endurance: 0, mentality: 0, intellect: 0, observation: -2, charm: 0 },     vertigo: { physicality: 0, endurance: 0, mentality: 0, intellect: 0, observation: 0, charm: 0 },     tunnel_vision: { physicality: 0, endurance: 0, mentality: 0, intellect: 0, observation: -3, charm: 0 },     flash_blindness: { physicality: 0, endurance: 0, mentality: 0, intellect: 0, observation: 0, charm: 0 },     shivering: { physicality: -2, endurance: -2, mentality: 0, intellect: 0, observation: 0, charm: 0 },     slurred_speech: { physicality: 0, endurance: 0, mentality: 0, intellect: 0, observation: 0, charm: -3 },     weak_knees: { physicality: 0, endurance: -2, mentality: 0, intellect: 0, observation: 0, charm: 0 },     cold_sweats: { physicality: 0, endurance: 0, mentality: -2, intellect: 0, observation: 0, charm: 0 },     confusion: { physicality: 0, endurance: 0, mentality: 0, intellect: -4, observation: 0, charm: 0 } }; // Listen for changes to all injury attributes const injuryAttrs = [     'winded', 'dizzy', 'groggy', 'disoriented', 'nauseous', 'blurred_vision',      'ringing_ears', 'vertigo', 'tunnel_vision', 'flash_blindness', 'shivering',      'slurred_speech', 'weak_knees', 'cold_sweats', 'confusion' ]; on(`change:${injuryAttrs.join(' change:')}`, function() {     getAttrs(injuryAttrs, function(values) {         // Initialize injury totals for each stat         let injuryPhysicality = 0;         let injuryMentality = 0;         let injuryEndurance = 0;         let injuryIntellect = 0;         let injuryObservation = 0;         let injuryCharm = 0;         // Loop through each injury and apply its effects if the injury is active         injuryAttrs.forEach(attr => {             if (parseInt(values[attr], 10) === 1) {                 injuryPhysicality += injuryValues[attr].physicality;                 injuryMentality += injuryValues[attr].mentality;                 injuryEndurance += injuryValues[attr].endurance;                 injuryIntellect += injuryValues[attr].intellect;                 injuryObservation += injuryValues[attr].observation;                 injuryCharm += injuryValues[attr].charm;             }         });         // Set the calculated injury attributes         setAttrs({             injury_physicality: injuryPhysicality,             injury_mentality: injuryMentality,             injury_endurance: injuryEndurance,             injury_intellect: injuryIntellect,             injury_observation: injuryObservation,             injury_charm: injuryCharm         });     }); }); // Initialize injury attributes when the sheet is first opened on('sheet:opened', function() {     setAttrs({         injury_physicality: 0,         injury_mentality: 0,         injury_endurance: 0,         injury_intellect: 0,         injury_observation: 0,         injury_charm: 0     }); }); </script>
1731563696

Edited 1731563715
GiGs
Pro
Sheet Author
API Scripter
First, you don't need to do this: // Initialize injury attributes when the sheet is first opened on('sheet:opened', function() { Just add a default value in each attribute (&lt;input type="number" name="attr_injury_physicality", value="0"&gt;). Avoiding sheet:opened when you don't need it is always good, and setting value="0" should be enough. The big problem you are likely struggling with is that attributes names in a fieldset are not whatever is in the name="attr_part" - A fieldset attribute name is made up of three parts - the repeating section name, the row id , and your assigned attribute name. So if you have a repeating_injuries fieldset, you could have the attribute name repeating_injuries_-gf7wy6tg8whwr_injury_physicality . When you want to grab an attribute in a fieldset in a repeating section, it is much more complicated. You'd need something like: on(`change:repeating_injuries:${injuryAttrs.join(' change:repeating_injuries:')}`, function() { Then inside that sheet worker, you need two loops: first use the getSectionIDs function to build an array of every attribute in every row (remember, you wont know how many rows there are initially), then send that array to getAttrs , then you need another loop to go through those attributes already found and see if your attributes are checked. I can't suggest code for this without seeing the html for your fieldset, but you'll find exhaustive help here: <a href="https://cybersphere.me/roll20/" rel="nofollow">https://cybersphere.me/roll20/</a>
Hello, been trying for a bit to get it to work, but I think I did it weird or something, here is what I changed it too &lt;script type="text/worker"&gt; &nbsp; &nbsp; // Define the possible injuries and their effects &nbsp; &nbsp; const injuryValues = { &nbsp; &nbsp; &nbsp; &nbsp; winded: { physicality: -2, endurance: 0, mentality: 0, intellect: 0, observation: 0, charm: 0 }, &nbsp; &nbsp; &nbsp; &nbsp; dizzy: { physicality: 0, endurance: 0, mentality: 0, intellect: 0, observation: -3, charm: 0 }, &nbsp; &nbsp; &nbsp; &nbsp; groggy: { physicality: 0, endurance: -2, mentality: -2, intellect: 0, observation: 0, charm: 0 }, &nbsp; &nbsp; &nbsp; &nbsp; disoriented: { physicality: 0, endurance: 0, mentality: 0, intellect: -4, observation: -4, charm: 0 }, &nbsp; &nbsp; &nbsp; &nbsp; nauseous: { physicality: -2, endurance: 0, mentality: 0, intellect: 0, observation: 0, charm: 0 }, &nbsp; &nbsp; &nbsp; &nbsp; blurred_vision: { physicality: 0, endurance: 0, mentality: 0, intellect: 0, observation: -3, charm: 0 }, &nbsp; &nbsp; &nbsp; &nbsp; ringing_ears: { physicality: 0, endurance: 0, mentality: 0, intellect: 0, observation: -2, charm: 0 }, &nbsp; &nbsp; &nbsp; &nbsp; vertigo: { physicality: 0, endurance: 0, mentality: 0, intellect: 0, observation: 0, charm: 0 }, &nbsp; &nbsp; &nbsp; &nbsp; tunnel_vision: { physicality: 0, endurance: 0, mentality: 0, intellect: 0, observation: -3, charm: 0 }, &nbsp; &nbsp; &nbsp; &nbsp; flash_blindness: { physicality: 0, endurance: 0, mentality: 0, intellect: 0, observation: 0, charm: 0 }, &nbsp; &nbsp; &nbsp; &nbsp; shivering: { physicality: -2, endurance: -2, mentality: 0, intellect: 0, observation: 0, charm: 0 }, &nbsp; &nbsp; &nbsp; &nbsp; slurred_speech: { physicality: 0, endurance: 0, mentality: 0, intellect: 0, observation: 0, charm: -3 }, &nbsp; &nbsp; &nbsp; &nbsp; weak_knees: { physicality: 0, endurance: -2, mentality: 0, intellect: 0, observation: 0, charm: 0 }, &nbsp; &nbsp; &nbsp; &nbsp; cold_sweats: { physicality: 0, endurance: 0, mentality: -2, intellect: 0, observation: 0, charm: 0 }, &nbsp; &nbsp; &nbsp; &nbsp; confusion: { physicality: 0, endurance: 0, mentality: 0, intellect: -4, observation: 0, charm: 0 } &nbsp; &nbsp; }; &nbsp; &nbsp; // The list of injury attributes &nbsp; &nbsp; const injuryAttrs = Object.keys(injuryValues); &nbsp; &nbsp; // Create the event string: triggers when any injury field in the repeating section changes &nbsp; &nbsp; // This will trigger on changes to `repeating_injurys:injury` and all `repeating_injurys:&lt;injuryname&gt;` attributes &nbsp; &nbsp; const eventString = `change:repeating_injurys:injury ` + injuryAttrs.map(attr =&gt; `change:repeating_injurys:${attr}`).join(' '); &nbsp; &nbsp; on(eventString, () =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; // Get all row IDs in the repeating_injurys section &nbsp; &nbsp; &nbsp; &nbsp; getSectionIDs('repeating_injurys', function(ids) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!ids.length) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // If there are no rows, set everything to 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setAttrs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injury_physicality: 0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injury_mentality: 0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injury_endurance: 0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injury_intellect: 0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injury_observation: 0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injury_charm: 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Build an array of attributes to fetch: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Each row has `injury` (the chosen injury type) and all possible injury attributes &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let allAttributes = []; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ids.forEach(id =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; allAttributes.push(`repeating_injurys_${id}_injury`); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injuryAttrs.forEach(a =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; allAttributes.push(`repeating_injurys_${id}_${a}`); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Now get all these attributes &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getAttrs(allAttributes, values =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Initialize totals &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let injury_physicality = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let injury_mentality = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let injury_endurance = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let injury_intellect = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let injury_observation = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let injury_charm = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Process each repeating row &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ids.forEach(id =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const chosenInjury = values[`repeating_injurys_${id}_injury`]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // If the chosenInjury is defined and in our list &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (chosenInjury &amp;&amp; injuryValues[chosenInjury]) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Check if this injury is active (value == 1) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const status = parseInt(values[`repeating_injurys_${id}_${chosenInjury}`], 10) || 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (status === 1) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const effects = injuryValues[chosenInjury]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injury_physicality += effects.physicality; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injury_mentality += effects.mentality; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injury_endurance += effects.endurance; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injury_intellect += effects.intellect; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injury_observation += effects.observation; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injury_charm += effects.charm; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Set the calculated injury attributes &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setAttrs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injury_physicality, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injury_mentality, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injury_endurance, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injury_intellect, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injury_observation, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; injury_charm &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; }); &lt;/script&gt;
1733338487

Edited 1733338547
GiGs
Pro
Sheet Author
API Scripter
My suggestion: describe what you are trying todo, without referring to the characteer sheet at all. Also, describe what you want to happen on the character sheet, in exhaustive detail, and we can probably help. Also look at my page: <a href="https://cybersphere.me/roll20/" rel="nofollow">https://cybersphere.me/roll20/</a>
1733442606
GiGs
Pro
Sheet Author
API Scripter
I see several issues with your sheet worker, but you need to explain in more detail what it is supposed to be doing. Also: Do not assume people know anything about the code you are using or what it does. Explain everything. Learn to use code formatting in posts for long codes - your posts will be easier to read and get more of a response. very importantly: post ALL html that is relevant. Here that means the inputs that hold your final values, and and the html&nbsp; for the repeating section. Be humble - people like me will ask invasive questions, and we want to help, but you need to do the preceding steps for us to help you.