hmm, ok Aaron, that's going on the right track I think, but it's returning every character (164 of them at least). How could I limit it to only those that have an entry in the player-name attribute?
Stephen,
I'm not sure I understand all of the code that you put up. It appears to work, but I'd like to understand how it works.
// Get all the 'player-name' attributes.
var playerNames = findObjs({
_type: 'attribute',
name: 'player-name'
});
// Get the set of IDs for characters for which the 'player-name' attribute is set.
// We use a set here to avoid duplicates.
var charIds = {};
_.each(playerNames, function(attr) {
if(!!attr.get('current')) {
var charId = attr.get('_characterid');
charIds[charId] = true;
}
});
// Return the Characters for each of the good character IDs.
return _.map(_.keys(charIds), function(charId) {
return findObjs({
_type: 'character',
_id: charId
})[0];
});
The first part just returns all the attributes that are 'player-name' attributes along with the character ID's associated with those attributes. Makes sense so far.
The second part returns 'player-name' attributes that have an entry. I've got a few questions here. I've read the underscore documentation, but I'm not quite clear on exactly how _.each works. The second question is, what does the '!!' before the 'attr.get('current')) {...' do? And then what is a set? is that the CharIds = {}?
As with _.each, I'm not sure how _.map functions, so I'm not really sure how the third part functions at all.
Thank you,
Scott