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

Generate Array of Current Character Tokens

I am trying to figure out how to grab the token information of player owned tokens such that i have the following information var playerTokenCollection = [     [token_display_name, token._id, character._id],     [token_display_name, token._id, character._id],     [token_display_name, token._id, character._id] ]; my understanding is that a player can own multiple characters and a single character can be represented by multiple tokens ?
CK said: my understanding is that a player can own multiple characters and a single character can be represented by multiple tokens ? This is correct
To add further complication (not sure if it impacts what you want to do), multiple players  can control the same character .
1519419630

Edited 1519419720
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
something like this should work: var grabber = function(){     var tokens = findObjs({type:'graphic',isdrawing:false}),         characters = findObjs({type:'character'});          characters = _.filter(characters,(c)=>{return c.get('controlledby') && c.get('controlledby')!==''});     tokens = _.filter(tokens,(t)=>{return (t.get('controlledby') && t.get('controlledby')!== '') || _.some(characters,(c)=>{return c.id === t.get('represents')})});     log('Player controlled Tokens: '+JSON.stringify(tokens)); }, You could further restrict it by limiting it to a page by including the pageid key in the tokens findObjs.
Thanks Scott, that works perfect!
1519441619
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
glad to hear it. Just passing on the lessons I was given when I started :)