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

Trigger script on token selection

As the title suggests, I want to trigger a script when I select a token. I know selected objects are stored in msg.selected when a message is sent. Is there another way to access this so I can avoid that step?

If not, I'm trying a work around where a setInterval function sends a message every second as a player and then that message event checks the msg.selected array to see if it contains the token I want.  However, the msg.selected for this technique keeps coming up undefined, even though I sendChat(player.id, "!checkSelected").

Any thoughts or ideas are appreciated.
June 09 (7 years ago)

Edited June 09 (7 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Nope, the API can only respond to chat messages or changes to the vtt. Selection doesn't count for that.

Aaron and Stephen experimented with ways to approximate this and came up with rotactivation and dragtivation.
June 09 (7 years ago)
The Aaron
Pro
API Scripter
Nope.  There is no way to know what the user interface is doing except at the point that a user sends an API command, or otherwise manipulates the state of the game. (moves a token, changes an attribute, etc)

There isn't a way to know during your interval what the player has selected.  When you issue the command !checkSelected from the API, it's the API that runs it, not the player. Putting player.id in the first parameter only sets what would be displayed at the left in chat, if it actually went to chat.  It doesn't change the context of the message.  The API never has anything selected.

If you need to know about tokens to manipulate, I might suggest keying off of tokens with a given status marker, and give players a way to toggle that.  You can use TokenMod for that:
!token-mod --set statusmarkers|!blue
June 09 (7 years ago)

Edited June 09 (7 years ago)
Thanks for the prompt responses! 

The game I'm making has a board with labeled columns and rows, and I wanted players to be able to click on the labels and set a value to that column/row.  It was just a time-saving/convenience thing.

*edit* I can make it work by dragging the textObj labels and triggering it in a change event.  Slightly less convenient but not bad.