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

Can I use sendChat from API to add to turn tracker?

I am using: sendChat(msg.who, "[[1d20 &{tracker}]]"); in the API in an attempt to add the selected unit to the turn tracker, but it just rolls the dice and ignores the "&{tracker}". Does this just not work or is it a bug?
1432531071
Lithl
Pro
Sheet Author
API Scripter
No. You have to manipulate the turnorder yourself.
The "&{tracker}" syntax requires a selected token, but messages generated by sendChat don't have selected tokens. However, you can add to the tracker yourself in one of two ways: 1) Pass a callback to sendChat, in which you grab the results of the roll you made and put the relevant token into the tracker wherever you want. When you pass a callback to sendChat, it doesn't display the message in the chat, so you'll have to make your own output if you want it. 2) Make the output of your sendChat unique enough that you can catch it in a global "chat:message" handler, in which you grab the results of the roll you generated and put the relevant token into the tracker. If you go this route, you'll probably want to put something into state that says you have a roll outstanding for a particular token (ideally including the entire command you sent so you can match against it in your "chat:message" handler) so that you don't accidentally grab arbitrary rolls sent by players or other scripts.