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

Newb Questions

I'm very experienced with Javascript, but this API is new to me. I want to create a custom script that rolls dice, chooses a result, then sends that result to the chat. I'm not sure the best way to invoke the script. I was hoping there was a "run macro" event I could listen for, but I haven't found it yet. I saw the API for sending something to chat. So I think I just need help understanding the best way to invoke this script when I want. It would be a global script, not linked to any characters or tokens. Simple set of dice rolls, then the output result to chat.
1546368774
Jakob
Sheet Author
API Scripter
For "run macro" type commands, you will want to listen to chat message events like this: on("chat:message", function(msg) { if (msg.type === "api" && msg.content.indexOf("!mysupersecretcommand") === 0) { doSomethingUseful(); } }); Then you can invoke it with !mysupersecretcommand parameters Note the exclamation mark, which marks this message as an API message, which does two things: first, the msg.type property is set to "api", second, the message is not actually visible in chat.
Perfect! Exactly the kind of help I was hoping for. Thanks.