Dealing cards via script

I've been building my first script to do setup for a game (Arboretum), and I'm absolutely stumped by something that I thought would be super easy. I have a deck of cards, and I want to deal cards out to the players. I'm using the API reference here: https://api.tabletopsimulator.com/object/#deal but it just has the effect of doing nothing at all.

I know my deck object is referencing the proper thing - I can flip it, shuffle it, and get its quantity. When I print its tag, it says it's of type "Deck". When I call the deal method, the response in code is "true", implying that cards were dealt. But the deck does not change size, and no players have any cards in their decks. I can deal cards manually in game from this deck, just not via script. I've tried every combination I can think of for the given deal() parameters - ignoring the optional params with variable numbers of seated players, looping over seated players and trying to deal to them by color or by id, etc. In every case, I get a no-op. No error, just nothing dealt.

What am I missing here?

Posted Mar 28, 2020, 10:51 PM UTC

00
rbbbt•

Can you show a code snippet?

1
galactoiseOP•

I actually ended up figuring out the issue after a lot of hair pulling with the folks on TTS Discord. The problem was that there was a hidden race condition with some of the deck management functions where their completion wasn't blocking, and the result was that the deck wasn't technically available to deal cards at the time I was making the deal call. There was no error messaging or anything, and debug logging wasn't revealing anything. I just at one point ended up putting thread waits in just for a sanity check and that caught it.

1