APISelection APISelection adds a simple interface for other scripters to use when creating scripts that operate on a persisted selection of objects, as well as sharing a list of selected objects across multiple scripts. At its heart, it is nothing more than a mapping from a string key, to an array of string s, with an interface to make manipulating those arrays easy. Public Interface APISelection has 5 public functions: getList( id ) -- Returns an array which represents that id . It will always return an array, even if nothing has been saved for that id . The returned array will always only contain strings. Manipulations of the returned array will not change the stored array. setList( id , list ) -- Sets the array for an id . The current array for the id will be replaced. Returns a copy of the stored array, as with getList( id ) . Only one copy of a value in the list will be retained, duplicates are removed. deleteList( id ) -- Removes the array for an id . Returns the emtpy array [] . removeFromList( id, list ) -- Removes the values in the list argument from the stored array for the id . Returns a copy of the stored array with the list arguments removed as with getList( id ) . addToList( id , list ) -- Adds the contents of the list argument to the stored array for the id . All duplicate values are removed. Returns a copy of the stored array with the list arguments added as with getList( id ) . Example Use on( 'ready' ,()=>{
APISelection.setList(
'party-characters' ,
findObjs({ type :'character'})
.filter( ( c )=> c.get( 'controlledby' ).length)
.map( c => c.id)
);
// ...
let partyCharIds = APISelection.getList( 'party-characters' );
let partyTokens = findObjs({ type :'graphic'})
.filter( t => partyCharIds.includes(t.get( 'represents' )));
// ... etc
});
Commands !api-selection Lists the current selection lists and their values. Mainly useful for scripters inspecting what is happening. Github Link: <a href="https://github.com/shdwjk/Roll20API/blob/master/APISelection/APISelection.js" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/APISelection/APISelection.js</a> Support my work on If you use my scripts, want to contribute, and have the spare bucks to do so , go right ahead. However, please don't feel like you must contribute just to use them! I'd much rather have happy Roll20 users armed with my scripts than people not using them out of some sense of shame. Use them and be happy, completely guilt-free! Disclaimer: This Patreon campaign is not affiliated with Roll20; as such, contributions are voluntary and Roll20 cannot provide support or refunds for contributions.