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: possible bug with pickUpCard()

1723935965

Edited 1724011496
re-posting this from bug reports & technical issues, on recommendation:  Hello. I'm currently scripting some extended functionality for playing cards. I'm taking it a chunk at a time, and currently am attempting to use the pickUpCard() function to pick up a selected card from the table when a script is called. Long term, more will be done with that card once it's removed, based on cardid, but for the basic functionality, the code looks like this: on("chat:message",function(msg){ if(msg.type=="api" && msg.content.indexOf("!tt")==0)      { //Get selected card         var selected = msg.selected;         var card = getObj("graphic",selected[0]._id); //log the card id for debugging         log("card type: " + card.get("cardid")); //pick up selected card via its cardid         pickUpCard(card.get("cardid"));     } }); this compiles fine and runs, but unexpected behavior occurs under certain circumstances. A single card is played from deck or hand The script is run with that single card selected. The card is removed and sent back to the deck list as though it was recalled. Exactly what I want to happen Multiple cards are played from the deck or the hand: the first card played is selected and the script is run. again, it functions as intended, recalling the 8 of spades to the deck as though "recall" were used (ignore that 10 of diamonds was selected in previous screenshot. It was just the last played when I took the screenshot. 8 of spades was selected when I ran the script) log of the last script run selecting and running the script on the next of the 3 cards. Nothing happens log of the "3 of spades" script run so for some reason, when multiple cards are played to the table, pickUpCard() will function for the  first  of these cards, but not for any subsequent cards. What is bizarre, is the get.("cardid") still pulls and logs the correct id for the selected card, but for some reason pickUpCard() does not recognize those cards as existing on the table. perhaps even more strangely, is after an erroneous run of the script, this behavior will reset and replicate, which is to say out of any  new  cards played to the table, the first of them will function correctly by pickUpCard(), while additional cards will not be recognized as existing, and likewise, the cards that failed to function previously will still not function.
1723946827

Edited 1723987346
timmaugh
Pro
API Scripter
The cardid is different from the id of that graphic on the table. The cardID is the ID of the actual card (the archetype), while the ID is the ID for the graphic (which is an instance of the card). If you want to see the properties, you can install Inspector (a script), select a card, and run: !inspect --selected That will show the selected property of the message. Use the link to expand the selection into the token (properties), and you'll see the type is a graphic (subtype: card), and it has an ID. The cardid will be another link that will expand the card archetype (the source object. That will show you the difference between them.  Which do you need? EDIT: Just found the documentation for the pickUpCard function, so I see you do, in fact, need the cardID.
1723948249
The Aaron
Roll20 Production Team
API Scripter
That is peculiar!  I will take a look at that function. Frankly, those functions have always have issues. I rewrote past of them for experimental, so I'd be curious to know if the behavior persists there as well. 
The Aaron said: That is peculiar!  I will take a look at that function. Frankly, those functions have always have issues. I rewrote past of them for experimental, so I'd be curious to know if the behavior persists there as well.  Thank you for looking into it, I really appreciate it. If anything, hopefully it's a simple fix or something that can be worked around, somehow
1724117732

Edited 1724117952
I also kept poking at it, and I made some progress in finding a way to possibly make this function for now: picking up from the middle steps, you play multiple cards from the deck. The first card works and cards 2:n on the table don't work with pickUpCard(). however, if you shuffle the deck at this point, the 2:n cards will  register as on the table, and be recalled by pickUpCard(). So I guess to make the function work as intended for now, I can use shuffleDeck() with an array matching the pre-shuffle order to trigger the cards on the table to be read as on the table. Hopefully that might also zero in on where any logic errors of the pickUpCard() function may or may not be, which is making only 1 card recognized before a shuffle