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

[Help] Remove Card from Table Top

1632012800
Finderski
Pro
Sheet Author
Compendium Curator
I've figured out how to play a card to the Table Top: //-=> Draw Card <=- cardID = drawCard(cardDeck["id"]); //-=> Got a Card <=- //-=> Play the Card to the Table let cardToPlay = playCardToTable(cardID, { left: tokenDeets.get("left") + tokenDeets.get("width") / 2, top: tokenDeets.get("top") + tokenDeets.get("height") / 2, currentSide: 0, width: 140, height: 198, }); I can't, for the life of me, figure out how to remove the card from the table top. From what I gather I need to use .remove(), but I no clue how to use that... I've tried things like: let dealtCard = getObj("card", cardID); dealtCard.remove(); But when I try that I get  TypeError: Cannot read property 'remove' of undefined I'm probably supposed to be a .get()...? Any help would be appreciated. :)
1632013552
The Aaron
Forum Champion
API Scripter
Cards on the table top are not card objects but graphic objects with a card subtype. You should always check that the thing you got back from getObj() (and findObjs() too, though there you can just check the length) actually exist: let dealtCard = getObj("graphic", cardID); if(dealtCard) { dealtCard.remove(); }
1632015647
Finderski
Pro
Sheet Author
Compendium Curator
I made that suggestion change, but dealtCard is still showing as undefined. let dealtCard = getObj("graphic", cardID); log("dealtCard: " + JSON.stringify(dealtCard)); dealtCard ? dealtCard.remove() : log("No card to remove");
1632016070
Finderski
Pro
Sheet Author
Compendium Curator
Another weird thing...when I made that change, it dealt two cards to the desktop, then when I hit the code to remove them, I got the No card to remove message, dealtCard shows as undefined, and I can't even manually remove the card images from the desktop, the Console says: Uncaught TypeError: Cannot read properties of undefined (reading 'deck')     at HTMLDocument.<anonymous> (app.js?1631558290:621)     at HTMLDocument.e.handler (base.js?1631109910:32)     at HTMLDocument.dispatch (jquery-1.9.1.js:3074)     at HTMLDocument.elemData.handle (jquery-1.9.1.js:2750) Even after refreshing the game, those images won't delete. When I put the getObj back to card instead of graphic, I can remove those cards from the desktop just fine and the dealtCard is no longer undefined. :-/
1632017142
The Aaron
Forum Champion
API Scripter
Probably what you have is a card id, so what your script is removing is cards from the deck. To find graphics on the tabletop that represent cards in a deck, you have to use findObjs() for graphics with the card subtype and a cardid that matches. You'll probably also want a pageid depending on what you're doing.