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 Section, Count up items that match criteria

1501929916

Edited 1501930053
GiGs
Pro
Sheet Author
API Scripter
I have a fudge character sheet, the skills are in a repeating section. each skill has a rank, which is an adjective, like "Mediocre", "Fair", "Good", "Great" and so on.  I need a sheetworker to count up the number of each. then I will display them under the skill list something like this: Poor: 3, Mediocre 4, Fair: 3, Good: 2, Great: 1, Superb: 0. But i have no idea how to count how many of each ranks there are. The name of the field is attr_skillrank, and the repeating section is called repeating_skills. Each rank also has a numeric value, like -1, 0, 1, 2, etc. which could be used for matching if that is easier. that is attr_skillvalue. I anticipate people will suggest using TAS, and I am willing to use it, I just have no idea to how to use it.
I know you can use this to do that, somehow... I'm not sure exactly how to make it track a particular attribute, but I know in the CSS Wizardy thread, it says it can be used to do that. HTML portion <div class="sheet-repeating-fields"> <fieldset> /*/line to be tracked/*/<span class="sheet-counter"></span> </fieldset> </div> CSS portion .sheet-repeating-fields {   counter-reset: sheet-rep-items; } span.sheet-counter::before {   counter-increment: sheet-rep-items;   content: counter(sheet-rep-items); }
1502146505

Edited 1502146544
Jakob
Sheet Author
API Scripter
I don't think counting via CSS would work, since you always have the same elements there either way (but I'm no good at CSS, so I might be mistaken). Here's how you can do it via workers (I don't know about TAS, so I can't help there): on('change:repeating_skills:skillrank remove:repeating_skills', () => { "use strict"; getSectionIDs('repeating_skills', idArray => { getAtrs(idArray.map(id => `repeating_skills_${id}_skillrank`), v => { let setting = {}; setting.number_poor = Object.values(v).filter(x => (x.toLowerCase() === 'poor')).length; setting.number_mediocre = Object.values(v).filter(x => (x.toLowerCase() === 'mediocre')).length; setting.number_fair = Object.values(v).filter(x => (x.toLowerCase() === 'fair')).length; setting.number_good = Object.values(v).filter(x => (x.toLowerCase() === 'good')).length; setting.number_great = Object.values(v).filter(x => (x.toLowerCase() === 'great')).length; setting.number_superb = Object.values(v).filter(x => (x.toLowerCase() === 'superb')).length; setAttrs(setting); }); }); }); This will set the number_poor, ... , number_superb attributes to the values you need (you can of course change the attribute names, this is just for demonstration purposes). You can then use spans with a name or readonly inputs to display the numbers
1502177158
GiGs
Pro
Sheet Author
API Scripter
Thank you very much Jakob, that's exactly what I needed.  I did drive myself crazy for a little wondering why it wasnt working, till i noticed the "getAtrs" typo you'd cunningly slipped in as a test... ;) I dont know how to use the line "setAttrs(setting)" - i s that supposed to dynamically fill an array of appropriately named boxes or spans somehow? I did use this the code below and it works fine, I'm just curious if you were hinting at a more elegant approach there. setAttrs({ "skills_terrible": setting.number_terrible, "skills_poor": setting.number_poor, "skills_mediocre": setting.number_mediocre, "skills_fair": setting.number_fair, "skills_good": setting.number_good, "skills_great": setting.number_great, "skills_superb": setting.number_superb, "skills_amazing": setting.number_amazing, "skills_epic": setting.number_epic, "skills_legendary": setting.number_legendary });
1502178360
Jakob
Sheet Author
API Scripter
Yes, that typo was totally  a test :D. No, setAttrs(setting) just hands over the setting object to setAttrs, my code (innermost bracket) is equivalent to: setAttrs({ number_poor: Object.values(v).filter(x => (x.toLowerCase() === 'poor')).length, number_mediocre: Object.values(v).filter(x => (x.toLowerCase() === 'mediocre')).length, number_fair: Object.values(v).filter(x => (x.toLowerCase() === 'fair')).length, number_good: Object.values(v).filter(x => (x.toLowerCase() === 'good')).length, number_great: Object.values(v).filter(x => (x.toLowerCase() === 'great')).length, number_superb: Object.values(v).filter(x => (x.toLowerCase() === 'superb')).length }); in your notation, if that makes sense to you. So, my setAttrs(setting) is complete already, there would have been no need to put anything else in there. Of course, your approach also works, it's just redundant.
1502247133
GiGs
Pro
Sheet Author
API Scripter
That does make sense to me, I wasnt sure how to name the boxes to capture the output. I tried "setting.number_poor"  - i never thought of trying it without the "setting." Thats much more elegant than typing them all out individually.