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

js function in html sending to chat

1550739232

Edited 1550739258
Hi, I have a problem. I read that it is possible to make js functions in html file and somehow send it to chat.  I am trying something like that: <div class="sheet-tab-content sheet-tab5">     <h3 style="width:98%">GM <button id="example" onclick="exampleClicked()">Example Button</button> </h3>     <table class="sheet-center" style="width:98%">         <tr>             <td>d</td>             <td>d</td>             <td>d</td>             <td>d</td>             <td>d</td>             <td>d</td>         </tr>     </table> </div> <script type="text/javascript">     function exampleClicked() {         var placeOfDamage = ["Head", "Chest", "Stomach", "Hand", "Leg"];         sendChat("GM", placeOfDamage[Math.floor(Math.random() * myArray.length)]);         // alert(placeOfDamage[Math.floor(Math.random() * myArray.length)]);     } </script> What I am trying to achieve: make several JS functions with build in arrays with system damage place system (and few others) as an advanced tool for GM. Results should be printed out to chat as in example. Is it even possible? Pasted code is inside one file: test.html
1550764238
The Aaron
Roll20 Production Team
API Scripter
What you’re attempting is in a Character Sheet, not the API. The API does have a sendChat() fubctuon which does what you want. Character sheets do not have that function and just either call an API script, or output a Roll Template, neither of which is driven by javascript. 
1550767761
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Just pointing out that access to the API and creating character sheets are both Pro subscription level perks.
If you just want client-side Javascript utilities for your GM to use (including the ability to call Roll20's chat functions) you don't have to involve Roll20 in any way. &nbsp;You can just write it as a TamperMonkey/GreaseMonkey client side hack. &nbsp;This means you would be working without support and in undocumented land, but it isn't rocket science since it is just Java Script stuff. &nbsp; If what you create is useful to a lot of people, consider contributing to&nbsp;<a href="https://github.com/SSStormy/roll20-enhancement-suite" rel="nofollow">https://github.com/SSStormy/roll20-enhancement-suite</a>
Yeah, I can make it even in Java and make it on web. But it is not a matter. When I was creating that code I wanted to make a connection with roll20 chat (API - even for usual users - without PRO subscription) to work correctly. But I am done with trying so. Anyway, thank you