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

Deck and Card API

I'm wishing to make a campaign based on the "Pathfinder Card Game" (PFCG) but creating the decks manually is going to be very painful. Instead I thought I'd investigate the API and see if it would make sense to (finally) jump out of the free tier to pro.&nbsp; Some needs that I'd desire to script up: + Create a new deck by drawing cards from one or more other decks based upon a weighted rollable table ("draw 30 blessing cards") + Add a card on the table to a players deck + Peek at top card etc. How realistic is this? Even if I could create a deck via API, that would probably make it worthwhile. Verification of seriousness of being able to use the API :) &nbsp;<a href="https://github.com/thomasmckay" rel="nofollow">https://github.com/thomasmckay</a>
1459702564
The Aaron
Pro
API Scripter
There are some limitations when it comes to decks, the biggest of which is the API cannot create Decks or Cards. &nbsp;That sounds like a severe limitation when it comes to dynamically creating decks, but you can get around it somewhat because the API can change all the important settings having to do with a deck or card. The way I would approach this is: 1) Create the master deck with all of the cards. 2) Create a deck with a "Blank" card in it (for use as a template). 3) [Repeat as needed] Create a deck for each player. &nbsp;Put some identifier in the name like [PFCG-P] so you know it's a player deck. Choose one of the following that makes the most sense: A) When a new card is added to a deck with [PFCG-P] in the title, set that card to duplicate the "Blank" card. &nbsp;Provide a rollable table the players can Roll to choose a card randomly and set a blank card in the deck for that player to the copy of the card from the master deck. B) When a new card is added to a deck with [PFCG-P] in the title, choose a card randomly from the master deck and set it to that card (bypassing the rollable table). To handle picking up a card from the table, you'd have a command that deletes the card then watches for an add event on the deck and sets the newly created card to the card that was "picked up". (possibly interrupting B above.) For peeking, you can use the Deck's&nbsp; currentIndex to get the id of the next card from&nbsp; currentDeck , then pull up the card with that id. There are a few manual steps but you should end up with a pretty usable setup. &nbsp;Since the manual steps are all in the GM's interface, you could probably write some helper javascript bookmarklets to automate adding cards and setting up decks and such. =D
You would do well to get in touch with Brian ; I think he's working on an API-supported PACG game.
Thanks! Just went "pro" and messaged @Brian to see if there is possible collaboration.&nbsp;
Very difficult to figure out the CRUD of this API. Once I figure it out, hopefully I can contribute to the docs.
1459730092

Edited 1459730257
Lithl
Pro
Sheet Author
API Scripter
thomasmckay said: Very difficult to figure out the CRUD of this API. createObj( type[String] , properties[Object] ) &nbsp;=&gt; creates an object of the specified type with the specified starting properties (some properties for certain object types are required) and returns the new object getObj( type[String] , id[String] ) &nbsp;=&gt; returns the object of the specified type and id findObjs( properties[Object] ) &nbsp;=&gt; returns an array of objects which match all &nbsp;of the specified properties filterObjs( predicate[Function&lt;boolean&gt;] ) &nbsp;=&gt; returns an array of objects which pass the predicate callback getAllObjs() &nbsp;=&gt; returns an array of&nbsp; all &nbsp;objects in campaign; not recommended for general use obj .get( property[String] ) &nbsp;=&gt; returns value for specified property obj .id &nbsp;=&gt; alias for obj.get('id') Campaign() &nbsp;=&gt; returns the singleton Campaign object obj .set( property[String] , value[varies] ) &nbsp;=&gt; sets the value of the specified property obj .set( properties[Object] ) &nbsp;=&gt; sets the value of multiple properties at once obj .remove() &nbsp;=&gt; deletes the object Note that while the documentation for object properties includes a leading underscore on all read-only properties (eg, _id and _type), the get and createObj functions insert those underscores automatically as needed. (obj.get('type') and obj.get('_type') are identical.) They still show up in log &nbsp;output and the POJO "prev" parameter passed to object change events, though.
1459732566
The Aaron
Pro
API Scripter
The only place leading underscores are actually requires is when registering an event on the change of that property: on('change:player:_online',function(p){ sendChat('Welcomer','Welcome to the game, '+p.get('displayname')); });
After searching the forums there seems to be suggestions that a page can be made visible to all or select players via API, is that true? Specifics on how to do this would be great. Also, I only see&nbsp;Campaign().get("playerpageid") and it's not clear how to get other pages. How would I get the current page being displayed for the GM. (Related to above since I want the script to access the current page that the player is viewing.) Looks very good so far and quite fun.
1459817277
The Aaron
Pro
API Scripter
A player is viewing the page that is specified in Campaign().get('playerpageid'), UNLESS their player id is a property of Campaign().get('playerspecificpages'), in which case they are on that page. &nbsp; See:&nbsp; <a href="https://wiki.roll20.net/API:Objects#Campaign" rel="nofollow">https://wiki.roll20.net/API:Objects#Campaign</a> The page the GM is on is a bit more tedious. &nbsp;player.get('lastpage') will tell you the page id of the last page that the player loaded as a gm. &nbsp;That sounds like lawyer speak I'm sure. &nbsp;The important implications are:&nbsp; 1) The GM may be logged in as a player (playerIsGM(playerid) === false) and thus is on a page as determined for players up above 2) The GM may have more than one browser/window/tab open and so the last page they loaded is in one browser instance but the page they are currently interacting with/looking at is different than what is reflected by 'lastpage'. See:&nbsp; <a href="https://wiki.roll20.net/API:Objects#Player" rel="nofollow">https://wiki.roll20.net/API:Objects#Player</a>
Messing with macros: I select a card on the page but it does not have a deckid property. Do I need to iterate over all decks to find where that cardid has come from? I'm hoping that once I have the deck I will be able to figure out how to recall that single card into a specific position (via the _currentdeck attribute?). Or maybe I should be adding custom attributes to cards as they're placed into play? (I haven't searched for this in example scripts yet so don't know if it's possible.)
1459897539
The Aaron
Pro
API Scripter
The card on the table is actually a 'graphic' with the subtype of 'card'. &nbsp;It does have a 'cardid' which you can use to get a 'card' object which has a 'deckid'. Card: <a href="https://wiki.roll20.net/API:Objects#Card" rel="nofollow">https://wiki.roll20.net/API:Objects#Card</a> You won't be able to adjust the '_currentdeck' attribute, it's read-only.&nbsp; You can add attributes to a character, which a card can be associated with. &nbsp;You can set properties on roll20 objects, but I don't know that there is any guarantee that they will be retained if the sandbox restarts. &nbsp;I prefer to store anything I want to keep in the state object (shared global object which is stored in firebase along with all the other objects in the sandbox). &nbsp;Be sure to use the state responsibly as everyone uses the same object. =D
I thought the card would have a deck too but I do not see it when I print out all the attributes. <a href="https://gist.github.com/thomasmckay/8aafac1e2923c1" rel="nofollow">https://gist.github.com/thomasmckay/8aafac1e2923c1</a>...
1459904089
The Aaron
Pro
API Scripter
The problem is you're not finding cards with findObjs(), you're finding more graphics with the subtype card: /* ... */ cardId = getObj("graphic", msg.selected[0]._id).get("_cardid"); sendChat("DeckBuilder", "YYYY: " + cardId); cards = findObjs({ pageid: _currentPage().id, type: "graphic", subtype: "card" }); /* ... */ Try something like this: /* ... */ cardId = getObj("graphic", msg.selected[0]._id).get("cardid"); sendChat("DeckBuilder", "YYYY: " + cardId); card = getObj('card',cardId); if(card){ cards = findObjs({ deckid: card.get('deckid'); }); log(_.pluck(cards,'id')); } /* ... */
Thanks, I was sure I had tried that. The "caveman" debugging and cut&paste dev is really painful. Related, I did file the suggestion in proper forum: <a href="https://app.roll20.net/forum/post/3210095/add-option-to-disable-ace-editor-when-editing-api-scripts" rel="nofollow">https://app.roll20.net/forum/post/3210095/add-option-to-disable-ace-editor-when-editing-api-scripts</a>
After continued poking at the API, I feel like I'm writing my own deck handling routines. My goal was to create a generic deck utility that could handle not only PFCG but other card games too. Unless I'm missing something there isn't, for example, a way to draw a card from a deck and place it on the table? Effectively I keep finding myself just using the deck as a bag-of-parts. That bag is starting to get in the way, though, so I'm using it just for initialization of the tabletop and then using scripting to track the actual play (creating my own discard pile, etc.). I think other card gamers would find this useful but is it worth the investment? I see hints across the wiki that a full-featured deck API is/was in the works? I'll push up my code to github[1] when I get it at least partially working. Guidance welcome. [1]&nbsp;<a href="https://github.com/thomasmckay/DeckBuilder" rel="nofollow">https://github.com/thomasmckay/DeckBuilder</a>
1460408510
The Aaron
Pro
API Scripter
It would be nice to have full API support for the Card Decks. &nbsp;Maybe make a suggestion? &nbsp;Here are some related ones: <a href="https://app.roll20.net/forum/post/1240005/enhanced" rel="nofollow">https://app.roll20.net/forum/post/1240005/enhanced</a>... <a href="https://app.roll20.net/forum/post/1292722/allow-te" rel="nofollow">https://app.roll20.net/forum/post/1292722/allow-te</a>...