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's a good resource to learn API scripting?

So, I'm really wanting to dig into this, but my knowledge base is sadly lacking, could someone point me to some good resources to educate myself?
1490907189
Lithl
Pro
Sheet Author
API Scripter
API scripts are really just JavaScript, so any resource to learn JS will be helpful.  Code Adacemy and  Mozilla Developer's Network are both great resources. API scripts are running server-side, so they don't have access to things like the document or window objects. You could look at a NodeJS tutorial (since that's what the API is running under), but most Node tutorials will be focused on creating a JS-backed web server or command line interface, which requires various Node modules you don't have access to, so learning base JS is probably more useful. It's possible you'll run into some corner-case that's a quirk of Node, though, so it's worth bringing up. (For example: I had an issue a while ago trying to store the value of setInterval. In almost every browser on the planet, setInterval returns a number. In Node, however, it returns an object.) Once you feel somewhat comfortable with JS in general, you can look at the  Roll20 wiki for documentation on how to use the functions available to you that interact with the VTT. You can also look at  Underscore.js , a utility library that's available in API scripts. The general structure of an API script is: on ( some event , function( event arguments ) { var foo = // Campaign (); // filterObjs (...); // findObjs (...); // getAllObjs (); // getAttrByName (...); // getObj (...); var newObj = createObj (...); var val = someObj . get (...); someObj . set (...); sendChat (...); log (...); }); In particular when studying baseline JS, note that Roll20 scripts use "log", not "console.log".
awesome, Thanks!