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

What is actually being listened to?

I have followed another post here on the Hit Dice helper ... i am curious in that script there is a Listener in place looking at something.  My question is, what is the actual data being listed to ... do you simply up arrow in chat and grab the code there?  Do you F12 the browser and click on the template where the output is displayed?  Or is it a set of data passed to the code engine that the script is parsing? Thanks in advance.
1587534931
The Aaron
Roll20 Production Team
API Scripter
API scripts are Event Driven.  There are various events they could have registered an even handler with, but the most likely is the "chat:message" event.  API scripts run on a server "in the cloud" and their only interaction with the game is by observing those events, and setting data on Roll20 objects.  Hope that helps.
it does and it doesnt ... like with the hit dice helper thing ... in a 5e game if you click on hit dice it rolls a dice ... now something is parsed somewhere with charnames and simple templates and the like .. i am just trying to get an understanding of where that part happens and the specific calls that are generated.  If that is via the chat:message  handler .. where can i get my eyes on what is going on under the hood so to speak.
1587535379
The Aaron
Roll20 Production Team
API Scripter
Here is a good place to start:&nbsp; <a href="https://wiki.roll20.net/API:Chat#Chat_Events" rel="nofollow">https://wiki.roll20.net/API:Chat#Chat_Events</a> The basic sequence of events is this: A formula is entered into chat (either manually, or via roll button, macro, etc) On submit, substitutions via Roll Queries or Attribute references are made Dice are rolled by the dice engine The message, with all substituted text and dice calculations finished is passed to each of the chat handlers The script does stuff using information in the message, if it wants to.
brilliant .. will check that out thanks
So .. got to this on('chat:message', function(msg) { &nbsp; &nbsp; Object.getOwnPropertyNames(msg).forEach( &nbsp; &nbsp; &nbsp; &nbsp; function (val, idx, array) { &nbsp; &nbsp; &nbsp; &nbsp; log(val + ' -&gt; ' + msg[val]); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; ); }); If that is running you can see exactly what is sent in the msg array on the api console ... for example, clicking on HitDice on my character sheet dumped this into the api console "content -&gt;&nbsp; {{rname=^{hit-dice-u}}} {{mod=D6+$[[0]]}} {{r1=$[[2]]}} {{normal=1}} charname=Torinn {{licensedsheet=Torinn|licensedsheet}} " "inlinerolls -&gt; [object Object],[object Object],[object Object]" "playerid -&gt; -M3OT7DNa34k1pEwXguH" "rolltemplate -&gt; simple" "type -&gt; general" "who -&gt; Hayden (GM)"
1587599707
The Aaron
Roll20 Production Team
API Scripter
Glad to see you're making headway! If you pass something that isn't a string to the log() function, it will JSON.stringify() it and output the results. That can be useful for seeing the full structure of things, particularly if you copy it out to JSON pretty print site.&nbsp;
1587606779
The Aaron
Roll20 Production Team
API Scripter
Note, it's particularly important to either directly log() Roll20 objects, or to call JSON.stringify() to see their contents. Roll20 object's are proxies for Firebase objects. Their properties are accessed and manipulated via the .get() and .set() functions, so are not directly accessible. (Except for .id). &nbsp;However, they implement.toJSON(), so you can get the representation by passing them to log() or JSON.stringify().
thx The Aaron That was even better ... on('chat:message', function(msg) {log(JSON.stringify(msg));}); simple script that shows the contents of the chat message ... heaps of interesting stuff in there ...
1587612713
The Aaron
Roll20 Production Team
API Scripter
Even simpler: on('chat:message', m =&gt; log(m));
one day i will put more time into learning coding properly again ...&nbsp;