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

[API] When dealt card, do X

I was wondering if this was at all possible? I have had a look through the forums (admittedly, fairly quickly) but didn't find anything to support my idea. Basically, I have 'Inspiration' cards that I am hoping to give my players. Ideally, I am looking for 2 effects. When a player is dealt inspiration, modify the 5th Edition 'inspiration' field to == "on" When a player spends/donates inspiration, set the above field to == 0 Also, is it possible to assign macro tokens to these cards? So something like the following could happen Player puts card onto table Player selects 'Spend' Macro kicks in, something like ?{Spend Inspiration to get Advantage on a|Attack Roll, @{selected|character_name} focuses on hitting their target!|Saving Throw,@{selected|character_name} tries to resist with all their might!|Ability Check, @{selected|character_name} concentrates!} Inspiration field would then be set back to 0 Is this even possible?
1587750877
The Aaron
Roll20 Production Team
API Scripter
All of those things are possible, someone would just have to write a script to support it.
I have taken a look at the API language, looks like JS? Fairly confident I could tackle it myself with some pointing in the right direction
1587773384
The Aaron
Roll20 Production Team
API Scripter
Excellent!&nbsp; Here's a few threads to get you started: <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> And of course, ask lots of questions here, we love to answer them!
Thanks Aaron, guessing it only takes pure JS?
1587780397
The Aaron
Roll20 Production Team
API Scripter
Yes, no impurities allowed! =D API scripts are most similar to Node Modules, in that they run without a DOM in a sandbox and are event driven.&nbsp; The only things you can interact with are Roll20 Objects (and a few functions that wrap Roll20 Objects, like sendChat() ).&nbsp; There are some helper functions in the form of underscore.js (but you really don't need that anymore because of ES6 support). All API scripts are concatenated together into a single big script that is executed once on the API Sandbox.&nbsp; After that initial execution, all behavior occurs because of the events that a script has registered for. For example this tiny script: sendChat('',"The API is running!"); Will only execute a single time. It will out put the message "The API is running!" to&nbsp; chat, and then it's done. On the other hand, this script: on('chat:message',m=&gt;log(m)); Will run every time something is sent to chat since it has registered a call back function with the 'chat:message' event. Understanding that is a big part of understanding how to write API scripts.&nbsp; Everything the API does is Action At A Distance.&nbsp; The scripts are running on a sandbox server out in the cloud which is connected to a running game as a pseudo-player, and only influencing things by changing the state of Roll20 objects in response to Roll20 events.
So pretty much the same principle google use with Apps Script (their bastardised JS)? In that its cloud-run with no DOM etc?
1587780858
The Aaron
Roll20 Production Team
API Scripter
I suppose so?&nbsp; Javascript: the Good Parts. =D&nbsp;&nbsp;
Right. I'll see what I can cobble together!&nbsp;
1587781624
The Aaron
Roll20 Production Team
API Scripter
Sounds awesome, I'm looking forward to it!&nbsp; Since you're dealing with cards, you might find these useful:&nbsp; <a href="https://app.roll20.net/forum/post/6223396/slug%7D" rel="nofollow">https://app.roll20.net/forum/post/6223396/slug%7D</a> Note that some of them are broken currently, so if you start to find one behaving counter to how you think it should, it's probably the one that's broken...
That's helpful, thanks!