I reached out to Aaron about this awhile back, but I haven't heard back yet, so I figured I might put it out in the open so other people can offer help as well! "I'm having an issue with the attrLookup() function you wrote a while
back, in which in certain cases it returns the secondmost item in a
repeating section instead of the first one. For reference, here's the
function: var attrLookup = function(character,name,caseSensitive){ let match=name.match(/^(repeating_.*)_\$(\d+)_.*$/); let returnval; if(match){ let index=match[2], attrMatcher=new RegExp(`^${name.replace(/_\$\d+_/,'_([-\\da-zA-Z]+)_')}$`,(caseSensitive?'i':'')), createOrderKeys=[], attrs=_.chain(findObjs({type:'attribute', characterid:character.id})) .map((a)=>{ return {attr:a,match:a.get('name').match(attrMatcher)}; }) .filter((o)=>o.match) .each((o)=>createOrderKeys.push(o.match[1])) .reduce((m,o)=>{ m[o.match[1]]=o.attr; return m;},{}) .value(), sortOrderKeys = _.chain( ((findObjs({ type:'attribute', characterid:character.id, name: `_reporder_${match[1]}` })[0]||{get:_.noop}).get('current') || '' ).split(/\s*,\s*/)) .intersection(createOrderKeys) .union(createOrderKeys) .value(); if(index<sortOrderKeys.length && _.has(attrs,sortOrderKeys[index])){ returnval = attrs[sortOrderKeys[index]]; if (returnval != undefined){ return returnval; } else { return "" } } } return name; }; It
seems to only do this with certain attributes and not others, but not
always; I've had the most trouble with the repeating_weapons_wtype
attribute on my Fire Emblem Tabletop sheet, but it's occurred sometimes
with other attributes. If there's only one repeating section, it seems
to work as intended. If you could help me with identifying this issue, I
would really appreciate it." Why it does this with some attributes but not others, I have no idea.