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 .
×

Javascript to induce chat

Hi, can one do it? I just found this post but no solution was posted, and I could not PM the OP. My hope is I can do something in the line of on("change:hitpounts... to induce a chat line like "/w gm hitpoints changes..." Is this possible? I am quite new to character sheet programming, but managed to update an original to my house rules. (Just to try to give you a hint on my level.) TIA Hardy
1611070129
GiGs
Pro
Sheet Author
API Scripter
There are two ways to use javascript in roll20, and its not completely clear which you plan to use. Sheet workers are built into character sheets, and cannot send anything to chat - they can only modify attribute values on the sheet.  API scripts can do many things that sheet workers cant, but only groups with a Pro-subscribing GM can use them.
1611075091
Andreas J.
Forum Champion
Sheet Author
Translator
Hardy said: I am quite new to character sheet programming, but managed to update an original to my house rules. (Just to try to give you a hint on my level.) Hope you have checked out the documentation on the wiki, there is tons there to read and learn the basics: <a href="https://wiki.roll20.net/Building_Character_Sheets" rel="nofollow">https://wiki.roll20.net/Building_Character_Sheets</a> <a href="https://wiki.roll20.net/Sheet_Worker_Scripts" rel="nofollow">https://wiki.roll20.net/Sheet_Worker_Scripts</a> - using JS inside sheets, as GiGs described it
Thank you both, yes I was vague about where… The outcome is what I want, no matter JS or some nifty HTML/css, in sheet or API. It is just that I fiddled in the sheet I thought I found the right hooks, and had hoped someone would say “Well yes, look at this example.” Seems not to be that simple :-( Thanks GiGs and ᐰndreas for pointing. Methinks I need to delve deeper into this stuff then. p { margin-bottom: 0.1in; line-height: 115% }
1611117568

Edited 1611117605
If you want to get a message every time a character's hit points change, that might be a lot of messages! If you have a character sheet value linked to a token bar, an API script can watch for changes to that token (I'm pretty sure that an API script can also watch a character sheets for changes, too, but I don't have that handy ;-). I use the following API script to monitor token speed and whisper to me if it changes. It's based on work from The Aaron (of course) in this thread: <a href="https://app.roll20.net/forum/permalink/6633790/" rel="nofollow">https://app.roll20.net/forum/permalink/6633790/</a> // SOURCE: <a href="https://app.roll20.net/forum/permalink/6633790/" rel="nofollow">https://app.roll20.net/forum/permalink/6633790/</a> on('ready',()=&gt;{ const isAddChange = (()=&gt;{ const THRESHOLD = 500; const createRegistry = {}; on('add:graphic',(obj)=&gt;{ createRegistry[obj.id]= new Date() * 1; }); return (id) =&gt; ( (new Date()*1) - (createRegistry[id]||0) ) &lt; THRESHOLD; })(); on('change:graphic:bar1_value',(obj)=&gt;{ if(!isAddChange(obj.id)) { SpeedMonitor(obj, true); } }); }); function SpeedMonitor(obj, noRep) { sendChat('SpeedMonitor', '/w gm ' + '&lt;div style="padding:3px 5px;border: 1px solid #000;background: #fff;"&gt;' + obj.get("name") + "&lt;br&gt;Speed changed to: " + obj.get("bar1_value") + '&lt;/div&gt;'); };
Thank you for the example and pointing. Too sad the API and sheet inline have such a disjunct scope. I will have a closer look at your suggestion, but guess it cannot manage what I want. I would really prefer to do this from the sheet. Does not need to be exactly chat, but any kind of visualisation to the GM (other than just a token bar). Would be nice it could cast a &amp;template.... Thanks everybody.
Are you not using token bars? Or are you using them to track other resources than the ones you want alerts for? Hit Points are one of the most common token bar usages, but it's your game! :-) I believe what you want is most likely possible. I would post a request for assistance over in the API Forum (<a href="https://app.roll20.net/forum/category/46806" rel="nofollow">https://app.roll20.net/forum/category/46806</a>). You may want to include a detailed example, as well as what game system and character sheet this is for. Good luck!
I took the HP just as a likely example. I definitely want to examine sheet content, not just token bars. API ammo is the best basic example, but it does not fire chat content by itself. Thanks for hinting the other forum. I thought and hoped this can be handled by the sheet, but it seems a sheetworker cannot fire a message to the GM by itself.