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

Making scripts, where to start?

Greetings! I would like to make scripts for a game I'm playing in roll20, and made researches about where to start. The problem is that I only find tutorials about how to add pre-made scripts and how to use them. I don't want to use others' scripts, I want to use ideas I'm getting while messing up around with basic functionalities. The only thing I know it's that it's in JavaScript, and I'm pretty good with this language, which motivates me. But I have no idea about which functions exist in the API. Can anyone give me the place where I should start please?
1633363526
The Aaron
Forum Champion
API Scripter
Fantastic!&nbsp; We can always use more people writing scripts! Here's a great introductory video by Nick Olivo:&nbsp; <a href="https://www.youtube.com/watch?v=jam2yx8btaQ" rel="nofollow">https://www.youtube.com/watch?v=jam2yx8btaQ</a> Here are three threads I think give a good starting discussion: <a href="https://app.roll20.net/forum/post/6605115/namespaces-novice-seeks-help-exploring-the-revealing-module-pattern" rel="nofollow">https://app.roll20.net/forum/post/6605115/namespaces-novice-seeks-help-exploring-the-revealing-module-pattern</a> <a href="https://app.roll20.net/forum/post/6584105/creating-an-object-that-holds-specific-character-dot-id-and-character-name/?pagenum=1" rel="nofollow">https://app.roll20.net/forum/post/6584105/creating-an-object-that-holds-specific-character-dot-id-and-character-name/?pagenum=1</a> <a href="https://app.roll20.net/forum/post/6237754/slug%7D" rel="nofollow">https://app.roll20.net/forum/post/6237754/slug%7D</a> The API is pretty well documented on the Wiki:&nbsp; <a href="https://wiki.roll20.net/API:Introduction" rel="nofollow">https://wiki.roll20.net/API:Introduction</a> While working on API scripts, keep in mind the mental model that the API is like a player off on the internet that reacts to what's going on in the game.&nbsp; It doesn't run in anyone's browser, and doesn't have access to the UI, has no keyboard and mouse.&nbsp; Structurally, API scripts are pretty similar to a Node module, in that they do not have a DOM, and are very event based.&nbsp; Also of note, all API scripts installed in a campaign are running in the same global scope. Ask lots of questions, we love to talk about API scripting here!
1633363562
The Aaron
Forum Champion
API Scripter
Also of Note, the API requires a Pro subscription, or at least a Game created by and Active Pro Subscriber.
The video mostly shows how to install scripts, but thanks for the links! I started to look at them and I'm slowly getting an idea about how scripts work! I will take my time to learn and then start making scripts :3 Anyway, from what I see for now, it seems to be mostly based on reactions (with the listener on()) and custom commands (with the event chat:message&nbsp;). To be honest, this is what I had in mind about what I want to do. Also, thanks for the note, but I'm aware that the API requires a subscription. I'm just currently waiting before taking one, but I will definitively take one soon ^^
Oh, just a quick question... If I edit and save a script while I'm connected to the game, do I need to leave and come back to reload the game to apply new scripts or they automatically run even if the game is already loaded? Does the event ready only triggers when the game loads or also when the script is saved?
1633370939
The Aaron
Forum Champion
API Scripter
You don't need to reconnect.&nbsp; The API, like a remote player, just reconnects and does its thing.&nbsp; The event 'ready' occurs when the API has loaded all of the state for a game into the API sandbox.
1633371226
timmaugh
Pro
API Scripter
Saving a script will reboot your sandbox, and for the most part that's all you'll need to do. If your game is running in a different tab, you can just navigate there and test your changes. Sometimes your sandbox will go stale (your scripts won't run) and require a reboot, but even that won't require a game refresh. You should only have to refresh the game screen if you leave it open for a long time (or put your computer to sleep).
1633371465
timmaugh
Pro
API Scripter
I'll add this link to Aaron's excellent suggestions: <a href="https://app.roll20.net/forum/permalink/9049444/" rel="nofollow">https://app.roll20.net/forum/permalink/9049444/</a> That's a discussion of planning a command line to isolate the data you need to handle your script's functionalities.
Alright, thanks for your replies, and thanks for the link timmaugh, some good extra stuffs to know~