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

Filtering list of attributes

1523455142

Edited 1523455297
I seem to be missing something painfully obvious here. var char = findObjs({ type: 'character', name: options.name}); if(char.length == 0) { //Throw error message and return. omitted for sake of brevity. } var charid = char[0].id; //May need this later, might just fold it into the below. var charattrs = findObjs({type:'attribute', characterid: charid}); log("DEBUG: charattrs: "+JSON.stringify(charattrs)); var attrnames = {"Strength" : "str_pool" //.... etc } var attrid = charattrs.filter(x=>x.name == attrnames[options.attrname]); if(attrid.length == 0) { log("DEBUG: No attr value found.") //This line triggers. If i take the stringified charattrs, parse it again in the console, and run the filter line, I get 1 result. I have verified that attrnames[options.attrname] is returning the correct name. ... ? (and yes, i know filterObjs exists; I'm pulling charattrs to later be able to look up repeating section elements by related fields without having to continually dip back to the source:      var skillid = charattrs.filter(x=>x.current == options.skillname);      options.skillvalue = charattrs.filter(x=>x.name == "repeating_skills_"+(skillid[0].name.split("_")[2])+"_skillpool"); [This is also failing, incidentally, but i havent gotten to the point of debugging this one yet.] )
1523455955
Jakob
Sheet Author
API Scripter
This is clearly some snippet out of larger code, so it's hard to decode what you mean, but one thing that's failing for sure is that you need to use x.get('name')  instead of x.name . (BTW, it's a good thing you're not using filterObjs, findObjs will be a lot faster in this situation. In fact, you should never  use filterObjs()).
And there it is. x is not a simple Object, which the stringify/parse obfuscates. Penny dropped. Much thanks Jakob!