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

A brave new adventure - learn scripting

1607177421

Edited 1607178029
In an effort to not be as annoyingly reliant on the big dogs on here (looking at you, Aaron,  timmauggh, Keith, Oosh, Victor, Jakob) I would like to learn how to script.   I have a basic understanding of CSS and HTML, but would like to jump in and learn. What are some good tutorial videos for scripting API that I can download into my brainpan?
1607177773
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I would look at ways to learn javascript. Things like code academy are good.
I'm working my way through Code Academy now. Glad to hear it is as useful as I had hoped.
1607178037
The Aaron
Roll20 Production Team
API Scripter
If you want API specific videos, Nick Olivo has a whole series of them:&nbsp;<a href="https://www.youtube.com/playlist?list=PLqhGF2nCu23kPeaUV_zIGwPRBZYUlcTGv" rel="nofollow">https://www.youtube.com/playlist?list=PLqhGF2nCu23kPeaUV_zIGwPRBZYUlcTGv</a>
Aaron for the win. Batting 1000, as usual.
1607178492
The Aaron
Roll20 Production Team
API Scripter
Here are a few other sites that might be fun and helpful: <a href="https://codecombat.com/play" rel="nofollow">https://codecombat.com/play</a> <a href="https://www.codewars.com/?language=javascript" rel="nofollow">https://www.codewars.com/?language=javascript</a> <a href="https://javascriptissexy.com/" rel="nofollow">https://javascriptissexy.com/</a>
1607186398
timmaugh
Pro
API Scripter
That's fantastic! Welcome to the journey! You've gotten a ton of good resource suggestions, so I will take a slightly different tack and talk about your development environment. Sometimes the difference between understanding and not understanding is just realizing that you understand... meaning the code behaves the way you expect it to, and you get the results you expect. A good IDE can help catch some errors (capitalization problems with variables, matching closures, etc.), and give you some good code navigation tools, too (peeking at a definition, going to a definition, renaming all instances, finding all implementations, etc.). Ask 10 programmers and you might get 10 different answers, but for my development I use Visual Studio Community (free). There are also online options like jsfiddle.net and codesandbox.io . Last, it helps to be able to isolate and get immediate results from a piece of code that might be causing&nbsp; you trouble. The MDN resources on javascript are extremely helpful in that they not only walk through the function you might have trouble with, but they have live, mini-dev editors that let you run code in an "immediate" way. And, of course, the community is here to help, too!
1607187546
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
My only advice is when you are learning, have a useful, achievable goal in mind. Something you want to have that doesn't exist already. Having a specific motivation will keep you going when you are struggling through any frustrating or tedious parts of the learning process.
1607189734
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
As timmaugh said, we've all got different ide preferences. Personally I prefer Sublime 3 (free as long as you don't mind the occasional "please buy me" popup) as my code editor. I will also recommend bookmarking the Google closure compiler as it's invaluable for chasing down those pesky synraxerrors
1607191318
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I code directly in the window, because I'm a caveman.
You guys! You are all the very best. I hope to start playing soon. I'm going to start by writing a custom spellbook in the vein of Nick Olivo's tutorials. That should give me a foundation to build on.&nbsp; You can expect occasional (frequent) advise and beta-testing once I get it going.
i just thought I'd add to this, I'm a month off my 50th birthday and until recently saw no reason what so ever to learn any form of coding.&nbsp; Then I found Roll20 and there is so much more I want to be able to do with it.&nbsp; I have now finished Codecademy's HTML course and I've just started their CSS course, one day next year, I'll start their Javascript course.&nbsp; It is never too late to learn, but sometimes you need a reason to start.&nbsp; So good luck with your own endeavours.
1607344319
David M.
Pro
API Scripter
Haha, me too - "Fire BAD!" But seriously, it doesn't take long before we have to start interacting with API objects that obviously don't exist in an external IDE, plus the cases that have visible effects in the Roll20 UI. How do you guys deal with that?&nbsp; Have you created some kind of epic Roll20 emulator/class that has all of these objects, properties, methods, events, etc. or something?&nbsp; keithcurtis said: I code directly in the window, because I'm a caveman.
1607350538
The Aaron
Roll20 Production Team
API Scripter
I code in VIM. I use ESLint (via a plugin) for syntax checking, and sometimes test locally with Jest and a custom mock environment.&nbsp; It's a little cobbled together at the moment, and I've not found the best way to integrate a completed script into it, but for taking smaller parts of a script and testing all the edge cases, it works pretty well.
1607362723
timmaugh
Pro
API Scripter
I had poked at the idea of a jsfiddle or a codesandbox project -- something that people could fork to emulate certain R20 processes in a way that would give greater access to troubleshoot along the way. I haven't spent much time with the idea yet, but how to otherwise represent visual elements would certainly be one of the challenges. You can see the testing Aaron utilizes from his screenshots. The question for a forkable R20 Emulator would be the benefit to people who would want to use the project to learn to code on R20, if at the same time they had to also learn to code test cases (itself a distinct skill and a way of thinking). ¯\_(ツ)_/¯ &nbsp; The final product would have to be some convergence of easy-to-use and enough-troubleshooting-benefit to make it worthwhile to people.
1607391982

Edited 1607393287
Oosh
Sheet Author
API Scripter
That kind of thing would be pretty amazing... though I guess it's also important that beginners learn which bits are JS and which bits are Roll20. I was thinking about writing some code to emulate some of the API's functions (mostly for learning/fun), then realised I have no idea how to set it up properly. Would you just create a module and use export? Or is there a smarterer way? One of the things I've struggled with a bit, since I don't know the fundamentals of programming, is actually setting up vscode to do what I want it to. For example, I installed underscore so I don't need to remove underscore methods from my code if I just want to do some console testing, via npm install underscore. But the underscore helpers will just error unless I have const _ = require('underscore') in the code. I did some searching on trying to get that into launch.json or something, but wasn't finding helpful results. Can one of you clever people point me in the right direction for getting underscore working globally without having to chuck that line in manually? I'd also like to get a const log = (text) =&gt; {console.log(text)} functioning globally (or at least folder/workspace wide), so I don't need to keep pasting that either. I keep finding Google results which are way too technical for me. I'm assuming this would be helpful to other beginners like me :) I did at least manage to get ESLint globals set up for all the Roll20 functions (pats self on back). It doesn't seem like setting up an IDE is done by many people with my painful lack of knowledge. All in all, I feel like I'm learning to cook without understanding the utensils. The pumpkin soup smells great, but why are you stirring it with a cheese grater? And... probably don't use a plastic bowl on the gas burner next time, Oosh. Oh... and I've only recently realised that .get() and .set() aren't Roll20 specific, and that Map objects are A Thing. I'm pretty sure that wasn't covered in Codecademy, or maybe I fell asleep in class.
Oosh said: ... Oh... and I've only recently realised that .get() and .set() aren't Roll20 specific, and that Map objects are A Thing. I'm pretty sure that wasn't covered in Codecademy, or maybe I fell asleep in class. I just pushed through the core of CodeAcademy.&nbsp; .get() and .set() were definitely core features in the Objects and Classes sections when I took it. They definitely make setting up and altering both so much easier.&nbsp; I just muddled through traspilation, but have absolutely no experience with nodes, and it brought back nightmares of coding in DOS when I was 10 years old (circa 1990).&nbsp; After that is modules...&nbsp; Still so much to learn. Gonna take a break from CodeAcademy to look through some of my API scripts to see if I can make better sense of them now... then off to start beating on the keyboard in search of a usable script I can call my own.
1607396083
The Aaron
Roll20 Production Team
API Scripter
Just to clear up any confusion, while Map exists and has .get() and .set() methods, it's not what Roll20 Objects are based on.&nbsp; Roll20's .get() and .set() have to do with Firebase, the (near) realtime database that is the backing store for all the synchronized Roll20 Objects that make up the game.
Thanks for the clarification, Aaron! BTW, I managed to track down why my previous ApplyDamage arg was not firing.&nbsp; There was an extra space in the sendChat command of that if() conditional. Now it works like a charm for firing an API command. Still can't figure out how to use it to remove a token marker using libTokenMarkers, though. I think it has to do with the .reduce(opts,args) conditional that defaults an arg to true. But progress is progress! The title of this thread was quite appropriate.&nbsp; This is a brave new adventure into a brave new world.
1607702935
Andreas J.
Forum Champion
Sheet Author
Translator
&nbsp;&nbsp;&nbsp; These tips resources could be added to the API related pages on the community wiki. Might do it myself if I remember later this weekend.