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

Repeating Sum Sheetworker Issue

1629240910

Edited 1629247514
Need some advice on the Repeating Sum sheetworker. For ref., HERE is the script. Here is my repeating field: <fieldset class="repeating_skills"> <div class="row"> <div class="col-1-11 padr padb center help" title="Check this skill against a target #"> <button type="roll" style="font-weight: bold;" class="text-button" name="roll_skill" value="[[d12 + @{skillrank}]]"> Chk</button> </div> <div class="col-1-11 center padr"> <input name="attr_skilltgt" class="checkbox help" type="checkbox" value="?{Input the Target | 1}"></div> <div class="col-1-11 padr"> <input name="attr_skillbonus" class="ul" type="number" value="0"></div> <div class="col-1-11 padr"> <input name="attr_skillrank" class="ul" type="number" value="0" min="0"></div> <div class="col-2-11 center padr"> <select class="center ul" name="attr_skillgov"> <option value="0" selected>---</option> <option value="@{agi_mod}">AGI</option> <option value="@{str_mod}">STR</option> </select> </div> </div> </fieldset> I cut out the divs that seemed irrelevant to me (to reduce the amount needed to get the gist). Below is the script I'm using to look for & calc my attributes. on('change:repeating_skills remove:repeating_skills', function() { repeatingSum("skillrank_total","skills","skillrank"); }); When I try to change the value of the "skillrank" input box, my "skillrank_total" box does not update to the new value. Do you guys see anything out of place? TIA
Nvm. I switched from GiGs script to TAS (The Aaron) & I no longer have a prob (using my same parameters). If GiGs or anyone else wants to take a shot at trying to figure out why I can't use my existing parameters with GiGs script, I'm open to suggestions (esp. b/c GiGs script is a LOT smaller, & I'd pref. that one). Until someone can help me track down what went wrong, I guess I'm sticking with Aaron's script.
1629263471

Edited 1629264426
Kraynic
Pro
Sheet Author
What does the skillrank_total attribute look like?  I think that is the only thing missing in what you have posted.
1629270316
GiGs
Pro
Sheet Author
API Scripter
I second Kraymic's question. I'm not seeing why the above code wouldn't work, so I'd like to see what skillrank_total looks like too.
1629312236

Edited 1629312619
<input name="attr_skillrank_total" type="hidden" value="0" readonly> **Edit** Yeah... I can't make heads or tails of it either. I'm not as savvy at writing JS as you guys, but I understand (very well) the structure / function of it, & I can't figure out for the life of me why GiGs shorter script won't work. I've doubled, tripled, quadrupled, etc. check all of my attrs & parameters, but cannot figure out why it isn't working... esp. when I can use the exact, same attrs, etc. in Aaron's script & it works. I'm baffled.
1629313237

Edited 1629313698
Gonna post it verbatim as I have it in my PC sheet (minus the head, body, etc. stuff) <div style="display: none;"> <input name="attr_skillrank_total" type="hidden" value="0" readonly> </div> <fieldset class="repeating_skills"> <div class="row"> <div class="col-1-11 padr padb center help"> <button type="roll" style="font-weight: bold;" class="text-button" name="roll_skill" value="&{template:DEPGold} {{name=@{pc_skillname}}} {{subtags=@{pc_skilladj} Adj ❖ @{pc_skillgov} Gov Mod}} {{check=Result: [[ d12 + (@{pc_skillgov}) + (@{skillrank}) + (@{pc_skilladj}) ]] }}"> Chk</button> </div> <div class="col-1-11 padr"> <input name="attr_pc_skilladj" class="ul" type="number" value="0"></div> <div class="col-1-11 padr"> <input name="attr_skillrank" class="ul" type="number" value="0" min="0"></div> <div class="col-3-11 center padr"> <select class="center ul" name="attr_pc_skillgov"> <option value="0" selected>n/a</option> <option value="@{pc_agi_mod}">AGI</option> <option value="@{pc_str_mod}">STR</option> <option value="@{pc_con_mod}">CON</option> <option value="@{pc_int_mod}">INT</option> <option value="@{pc_wis_mod}">WIS</option> <option value="@{pc_cha_mod}">CHA</option> </select> </div> <div class="col-5-11 padr"> <input name="attr_pc_skillname" class="ul" type="text" placeholder="Skill Data"></div> </div> </fieldset> <script type="text/worker"> <!----------------------------------------------------------- REPEATING-FIELD SUM SYSTEM ------------------------------------------------------------> const repeatingtotal = (destinations, section, fields) => { if (!Array.isArray(destinations)) destinations = [destinations.replace(/\s/g, '').split(',')]; if (!Array.isArray(fields)) fields = [fields.replace(/\s/g, '').split(',')]; getSectionIDs(`repeating_${section}`, idArray => { const attrArray = idArray.reduce((m, id) => [...m, ...(fields.map(field => `repeating_${section}_${id}_${field}`))], []); getAttrs([...attrArray], v => { const getValue = (section, id, field) => v[`repeating_${section}_${id}_${field}`] === 'on' ? 1 : parseFloat(v[`repeating_${section}_${id}_${field}`]) || 0; const commonMultipliers = (fields.length <= destinations.length) ? [] : fields.splice(destinations.length, fields.length - destinations.length); const output = {}; destinations.forEach((destination, index) => { output[destination] = idArray.reduce((total, id) => total + getValue(section, id, fields[index]) * commonMultipliers.reduce((subtotal, mult) => subtotal * getValue(section, id, mult), 1), 0); }); setAttrs(output); }); }); }; /* ================================== RPT FIELD ATTR PARAMETERS ====================================== */ on('change:repeating_skills remove:repeating_skills', function() { repeatingSum("skillrank_total","skills","skillrank"); }); </script> **Edit** I've tried several combos, incl. manually replacing the ${section}, ${id}, etc. with a direct attr; e.g. ${skills}, ${skillrank_total}, etc.. I even tried making the attrs look more like JS, by changing them to things like "skillRank_Total", "skillRank", etc.. I didn't figure it made any difference, but I've been so h3llbent on trying to make GiGs script work, I started trying ridiculous things, lol, to make it work. After 20 (or so) attempts, I said screw it, & tried TAS, since it was the only other option I had, outside of fumbling to make my own JS (which would NOT be pretty, lol).
1629313588
Kraynic
Pro
Sheet Author
I don't know.  It sure seems to work for me.  I did change the "hidden" to "number" so that I could easily see if it was changing (I left it readonly), but I think that was all I changed in your code.  This was what I tested: <input name="attr_skillrank_total" type="number" value="0" readonly> <fieldset class="repeating_skills"> <div class="row"> <div class="col-1-11 padr padb center help" title="Check this skill against a target #"> <button type="roll" style="font-weight: bold;" class="text-button" name="roll_skill" value="[[d12 + @{skillrank}]]"> Chk</button> </div> <div class="col-1-11 center padr"> <input name="attr_skilltgt" class="checkbox help" type="checkbox" value="?{Input the Target | 1}"></div> <div class="col-1-11 padr"> <input name="attr_skillbonus" class="ul" type="number" value="0"></div> <div class="col-1-11 padr"> <input name="attr_skillrank" class="ul" type="number" value="0" min="0"></div> <div class="col-2-11 center padr"> <select class="center ul" name="attr_skillgov"> <option value="0" selected>---</option> <option value="@{agi_mod}">AGI</option> <option value="@{str_mod}">STR</option> </select> </div> </div> </fieldset> <script type="text/worker"> const repeatingSum = (destinations, section, fields) => { if (!Array.isArray(destinations)) destinations = [destinations.replace(/\s/g, '').split(',')]; if (!Array.isArray(fields)) fields = [fields.replace(/\s/g, '').split(',')]; getSectionIDs(`repeating_${section}`, idArray => { const attrArray = idArray.reduce((m, id) => [...m, ...(fields.map(field => `repeating_${section}_${id}_${field}`))], []); getAttrs([...attrArray], v => { const getValue = (section, id, field) => v[`repeating_${section}_${id}_${field}`] === 'on' ? 1 : parseFloat(v[`repeating_${section}_${id}_${field}`]) || 0; const commonMultipliers = (fields.length <= destinations.length) ? [] : fields.splice(destinations.length, fields.length - destinations.length); const output = {}; destinations.forEach((destination, index) => { output[destination] = idArray.reduce((total, id) => total + getValue(section, id, fields[index]) * commonMultipliers.reduce((subtotal, mult) => subtotal * getValue(section, id, mult), 1), 0); }); setAttrs(output); }); }); }; on('change:repeating_skills remove:repeating_skills', function() { repeatingSum("skillrank_total","skills","skillrank"); }); </script> As you can see I just added 3 lines in the repeating section (1, 2, 3) for the skill rank value, and it totaled them up to 6.
Weeeeeeeeeeeeeeeird. That just makes it more infuriating, lol.
1629314822

Edited 1629315677
Well... apparently there's some kind of conflict (that I don't see) with the other sheetworkers I have (e.g. I also have a worker that handles calcs from option menus), & I'm tired of fighting to make GiGs script work (e.g. been working on this one prob for 2 days, & have tried about 30 combinations / "fixes" at this point). I REALLY want to use it b/c it's a helluva lot smaller than TAS, but it seems I don't have a choice. Gotta go with what works (short of trying to type up my own script; which would be REALLY messy, lol; my JS is really rusty ~ but I have a good understanding of the syntax when I'm looking over a script). Anyway. Thx for trying. **Edit** Not a sheetworker conflict. I just erased all but the repeating sum script & have the same prob. Oh well. Siiigh.
1629316557

Edited 1629317377
GiGs
Pro
Sheet Author
API Scripter
Here's your problem (you're probably going to slap your forehead). You've changed the name of the function from repeatingSum: const repeatingtotal = (destinations, section, fields) => { But you are still calling repeatingSum in your worker: on('change:repeating_skills remove:repeating_skills', function() { repeatingSum("skillrank_total","skills","skillrank"); }); You're calling a function that doesn't exist. Either change the function name back to repeatingSum, or change the call in your worker to repeatingtotal("skillrank_total","skills","skillrank");
1629316631
GiGs
Pro
Sheet Author
API Scripter
Kraynic said: I did change the "hidden" to "number" so that I could easily see if it was changing (I left it readonly) This is a good technique - I always do it when testing sheet workers that change hidden attributes, if I'm not sure something is working.
1629317248

Edited 1629317604
**Edit** Just noticed the slap comment. LOL. Actually... it was more of an exasperated sigh (a really long one, lmao). Ah... Good catch! Thx. I think I botched that up in my text editor when I was changing some of my attrs (that ended in the word "Sum"). I must have inadvertently also changed the script. Yeah. I had my "hidden" attr set to "number" for a while to try & observe any changes. That was part of my frustration. WOW !! That was a lot of frustration for such a simple oversight. The funny thing is that I noticed that several times & thought it looked off, but my brain kept telling me I'd done a direct copy from the Wiki, so it "couldn't" be wrong, lol. Thx a mil GiGs (& Kraynic). I like a lot of Aaron's contributions, but in this case, I REALLY wanted to use your shorter script GiGs (for a lot of reasons), lol.
1629317513
GiGs
Pro
Sheet Author
API Scripter
Proelium Ex Deus (Ares) said: Ah... Good catch! Thx. I think I botched that up in my text editor when I was changing some of my attrs (that ended in the word "Sum"). I must have inadvertently also changed the script. Aha, I wondered why it's name had changed. That makes sense - I've made find/replace name change errors so many times :)
1629317838

Edited 1629317863
Kraynic... did you not have the same prob I did? The error is in that script I C/P'ed. You must have changed it without thinking, lol. And yes GiGs... it was a VERY long, exasperated sigh I let out on reading your response (& instead of a slap, I just buried my forehead in my hand, lol).
1629329142
Kraynic
Pro
Sheet Author
To be honest, I copied the first part of the sheetworker from the wiki instead of from your post, because I was testing and composing my post while you posted the entire code.  I didn't see that until after I posted, so I was going from your very first post.  No issues at all.
Ah... gotcha. Well, it got worked out. Thx for you guy's time.