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/Bug?] drawCard/giveCardToPlayer API not working with unlimited decks ?

Hello, I have set a Deck as Unlimited. It contains three cards. (three kind of bennies I deal to my players in my SavageWorlds game) I wrote an API that drawCard(deckId, cardId) and deal them to players (using giveCardToPlayer). It works for the first time. Then it fails with error "That card is not in the deck.". Using cardInfo (with discard:true active) to collect cards from the deck, I see the card is no longer there, not even in the discard. However, in game, the card IS in the deck (and it is still in the my hand too). It looks like giveCardToPlayer does not take into account the deck is unlimited and shall "duplicate" the card before giving it to the player ? Help !
1566224391
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Try shuffling the deck. You may need to do it as part of the script process. I've only worked with finite decks and infinite decks of one card.
I do shuffle : I draw, if I can't, I shuffle and draw again. It doesn't change anything. I tried to shuffle directly before drawing the firs time, doesn't change. The "That card is not in the deck." error I get on the first draw and on the second draw (the one after shuffle).
1566226958
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Rats, I was hoping that would be the issue. I approached this by using a different deck for each kind of Inspiration (5e, not SW).
But in the deck you actually want to draw a random card. You have multiple cards, and usually far enough that they are not all in players' hand. I could work around by duplicating the benny cards until I have "more than enough", but it's sad. Also if I don't use the helper methods, and do update the player hand myself, everything works fine, players can drop them on the table and I get "delete" them, just fine.(however I didn't test to "recall" the cards, f.e. so there still might be side effects).
1566321298
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Hmm. I just created a 3 card infinite deck with my dealer script. It seems to give out an infinite supply of random cards without reporting an error. You can look and see if I have done anything differently. I'm not that quick at "de-coding" yet.
Hmm, thank you very much, that you tried it out. I'll have a look at how I did it, and see if I misused something.
Hi. I made some tests. This works : card = draw(deck), then give(card, player), then draw(deck) again then give again (i.e. dealer.js script from Keith) draw(deck, card), then give. but it only work once directly give(card, player) as many times as you want without even drawing This does not work : draw(deck, card); give(card;player); draw(deck,card); → error message in sandbox console :  "That card is not in the deck." shuffle(deck); draw(deck, card); give(card;player); shuffle(deck); draw(deck, card); → error message in sandbox console : "That card is not in the deck." When going with draw(deck) aka "draw from top", you can draw as many as you want, as long as you shuffle when deck is empty, your unlimited deck behaves as expected. When going with draw(deck,card) aka "draw a specific card from deck", the unlimited decks are not supported, the card disappear as soon as you give it to player, you can't draw a second one. Strangely, you can give cards to player without drawing them at all. And I can recall them fine manually from the interface. So I would say it looks like draw(deck, card) is buggy and can be skipped. I posted a sample code as gist on github . !dealbug --PlayerName --DeckName --CardId // example : !drawbug --Gronyon --Bennies --Lm_-7zWgNapY6CH-9yS // to get a card id, simply skip the last arg, and you'll get a list !dealbug --PlayerName --DeckName --CardId Each call will deal 2 cards to the player. Deck must be set as Unlimited. Here is a screenshot where I run it twice.  First pass, first card is drawn succesfully and given to player. Second card fails. Second pass, both attempts failed.
So I created a bug entry in the bug forums . And until fixed or given an answer, I can work with giveCard(card, player) without drawing :)