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

Selecting a token through the API

Is it possible to select a token on the page using the API? What I would like a script to be able to do is, using the add:graphic event, select a token as soon as it is dropped onto the page. 
1465332780

Edited 1465332808
Can't do that. You can get the token as an object in a script, but you can't force the token to be selected by your mouse when it hits the map.
Ok, thanks. How could I get the token as an object in a script, or where could I find that info in the documentation?
1465346202
Lithl
Pro
Sheet Author
API Scripter
API:Objects#Finding/Filtering Objects documents the functions getObj(type, id) , findObjs(attrs) , filterObjs(callback) , and getAllObjs() . getObj will return the object you're looking for, but you need to already know the object's ID findObjs will return an array of objects that all have properties matching the parameter passed to the function filterObjs will return an array of objects that return true when passed to the callback function getAllObjs will return an array of every object in the campaign There's also Campaign()  which will return the singleton Campaign object. In a chat:message event, you have access to the array of graphics selected by the user who triggered the message (with msg.selected), and you can pass IDs of graphic objects to a chat:message event using @{target|token_id} and @{selected|token_id}, or character objects if the tokens are linked to characters with @{target|character_id} and @{selected|character_id}.
Thanks!
1465490633
The Aaron
Pro
API Scripter
And for completeness, you can get the object via the  on('add:graphic',...) event.