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

Game Logging Question

Hello! Brand new here. I just started coding 3 months ago and have made my own char sheet using HTML/CSS/JS as a project. Is there any way to install an API into my code that allows me to log rolls? i.e. I press Stealth on my webpage, and the roll result shows on to the chat log on the right. I have considered  building a character sheet of my own , but that's not what I'm curious about.  Thank you for having me, and I'm excited to meet those who comment :)
API Scripter
To describe your setup... your character sheet is completely outside of Roll20. You interact with it as a web page, including generating rolls for your skills/attacks/checks/etc. Is that accurate? From outside (not from inside the VTT) you can modify the DOM, but if you injected elements in the chat pane you would only be doing that locally. Your remote players wouldn't see it. You might be able to chase down the event handlers to find the function that would let you initiate a sendChat() remotely, so that Roll20 propagated your result to all screens attached to your game... I've never tried something like that, but I think there are a couple of people around who have explored the "build a R20 extension" route... which might have a lot of bearing on what you're trying to do. Buuuut... it might also just be easier to build a sheet in the VTT and then build a way to port your off-site character data from your remote sheet to a character in your game.

Edited 1663898696
Sheet Author
API Scripter
The easiest way to do this is an extension, as Tim mentioned. Roll20 don't provide a public API to hook in to a sheet or in to chat, so you need something running in Roll20 to receive that roll request. That's probably a dummy player logged in, running an extension or monkey script. Once your roll request is received the rest is dead simple, just target the chat input element, paste the roll text in, and send a click event to the 'send' button. This sends a chat message just as if a human had typed it. I'd recommend using jQuery for the DOM events (I feel dirty saying that) because that's what Roll20 uses - using vanilla JS means a heap of events (like the click() event mentioned) won't actually trigger any internal handlers. Communicating between the webpage and the dummy Roll20 player is going to be the trickier part. You have a bunch of options here. If the browser running the dummy player also has the webpage open in a tab, you can send messages bebtween tabs with a browser extension to communicate between the two. This is probably your simplest option. What are you trying to achieve by emulating a character sheet with an external web page, out of interest? That's bascially building a character sheet, with added difficulty. You'll either need to understand some backend stuff, like connecting with websockets, or the browser extension world.
Thank you both for replying! @timmaugh Yes its 100% web-hosted, currently it has no relation to roll20. The sendChat() you mentioned is what I am seeking. Unfortunately Oosh suggested it doesn't exist.  It would probably be easy to build a page in roll20, since I have all the code already. Is it as simple as copy/pasting code, then changing functions to roll20's internal ones? @Oosh Would one dummy player do the trick? The GM could initialize it. The character sheet already handles player's names, data storage, rolling math etc. All I need is something that broadcasts a specific string I feed it. (or maybe even a .png behind a string to show the picture of the die rolled, and of course some :hover text lol).  My first HTML/CSS/JS project was a dice roller, with the full range of tabletop dice. Since I had the math & functions in place to make rolls, I decided to keep going. I also would prefer to have a seperate window open for my char sheet. Making a project is one thing, but its usefulness is the goal, youknow?
I just read this  This  about the sandbox method. Seems my plan won’t work after all! I do appreciate the Developers protecting people’s computers by keeping everything in the sandbox.

Edited 1663913113
Sheet Author
API Scripter
Josh said: Thank you both for replying! @timmaugh Yes its 100% web-hosted, currently it has no relation to roll20. The sendChat() you mentioned is what I am seeking. Unfortunately Oosh suggested it doesn't exist. Just to clarify this - sendChat() certainly does exist, it just isn't a public-facing API, it's a sandbox method limited to user-written sandbox scripts. You can use that instead of piggybacking the DOM to post something to chat, but that's only simplifying the easy part. You still need an active player inside the campaign to trigger the sandbox script to do the sendChat - that means you still need to solve the problem of your website communicating with the player in the game. If you want to use a single dummy account to roll every sheet, just create a second account and promote them to GM in the game - that gives them access to all character sheets automatically. As long as you create the game from your main Pro account, all Pro features would still work. Whether you go the sandbox/sendChat route (probably better since you have more options for the message format) or the DOM method to post to Roll20 chat, you still need a script or extension to either be listening for a postMessage, or open a websocket (or similar) back to your server - that's the complicated part, as you need to be able to push messages to your Roll20 listener account on demand. I don't think the message API works between separate instances of a browser- it's for popups & iframes to communicate with the main window. Likewise the tabs API is limited to the same instance of the browser. I haven't used either extensively, so it might be worth reading up on them. A websocket connection from the listener account to your server would be ideal, but is complex if you haven't delved into that before, and also depends on exactly what kind of web host you're using.
Forum Champion
There is an extension that may work similar to how you envision called Beyond 20. It is an extension to connect DnD Beyond character sheet rolls to Roll20.  I don't know if you could take a look at how it is set up or not, but if you could you might get some ideas on how to set things up for your own setup. 
Thank you both for this wealth of knowledge. I'll begin my research with this. It's a little disheartening to know this isn't as simple as making a bot that posts to discord, nevertheless I'll give it my all. If I ever get it working, I'll be sure to post my character sheet here along with the methods I used to create the sendMessage() magic :D