"Draw A Card" button; how to reshuffle discards automaticall

I have a single deck which cards are drawn from using buttons throughout the module (one button draws cards to your hand, another draws a card directly into the discard pile but reads it’s value to the chat, etc.).

I would like these draw buttons to be able to detect if the deck is empty and, if so, reshuffle the discards before performing the draw action.

Is this possible?

I imagine so. You’d probably change your “Draw” buttons to have 2 triggers, each with a different property match expression (PME) that references the number of cards in the deck (accessible via <deck-name-here>_numPieces).

The first trigger would be the case when your deck has 1 or more cards left, i.e. <deck-name-here>_numPieces > 0. In this case draw normally.

The second trigger’s PME would be <deck-name-here>_numPieces = 0. In this instance, you fire a GKC or something that is applied to all cards in the discard pile which activates either the Send to Location or a Return to Deck trait on every single card, sending it shooting back to the deck. Then draw normally.

There are probably more ways to approach this, but it’s what came to me off the bat.

How do I create a trigger on a button? Or is the button just a single global key command button and I put the triggers on the ‘Card’ prototype?

The “buttons” i’m referring to here are buttons placed into the window itself (Global Key Commands), not game pieces which have the ‘button’ trait.

Ah, do you mean buttons in your toolbar? Well, then perhaps the strategy is combine everything you need to do in a Multi-Action Button, which simply hides and carries out multiple GKCs bound to their own toolbar buttons in a sequence.

The Multi-Action button would call other buttons that:

  1. Does a GKC to fire the “go back to the draw pile” keystroke on all cards in the discard–but with a PME that the draw pile must be empty, otherwise this is a do-nothing button
  2. Does a GKC to fire the “draw 1 from the deck” command.

End result is a single button that draws 1, but also silently returns all the discards to the deck first if necessary. I’m a bit pressed for time to mock something up but it feels like that should be what you need.

Thanks for the help Joel. I’m not certain how to setup the PME you wrote about. Is that using the “Matching Properties” box and an “if” statement about number of pieces in a deck? I can figure out what to put into the ‘if true’ section, but what if the number of pieces in the deck is not 0? How do I setup the ‘false’ section of the if statement to ensure it doesn’t fire anywhere? Just write in a deckname which doesn’t exist?

I tried setting it up like I just described, but the problem is that I can’t get it to apply the command to the whole deck. The cards have a ‘return to deck’ trait mapped to CTRL+SHIFT+R, and using that I can get the global hotkey button to work with this property match: {If(GetProperty(“Main Deck_numPieces”)==0,DeckName==“Discard”,DeckName==“Main Deck”)}. I had the ‘fail’ condition to just have cards in the main deck go to the main deck (so nothing happens).

However, an ideal situation would be to trigger the actual ‘reshuffle’ function of the deck itself. I have been unable to trigger that with global key commands though. That is bound to CTRL+R, and if I press that key anywhere in any window, the discards shuffle back into the main deck as expected. However, global hotkeys which trigger Ctrl+R can’t seem to ‘target’ the deck reshuffle function and I’m not sure why. It seems like global hotkeys only target pieces and not decks.

Hmm, can’t edit anymore: To clarify…

While using a GKC on a player hand window with property expression set to: {If(GetProperty(“Main Deck_numPieces”)==0,DeckName==“Discard”,DeckName==“Main Deck”)}

The result is that it will only shuffle a single card from the discard back into the main deck, even though I have it set to target ‘all pieces’ of a deck. This suggests that it’s re-checking the ‘if’ statement for every piece, and I’m not sure hot to word the property match to get the result I want.

I’ll have to throw together a proof-of-concept to see if what I’m sketching out even works, otherwise I’ll just be saying more stuff that might sow more confusion (and it might not even be right)!

Totally different tack here–can you not just use the “Send hotkey when empty?” feature of a deck? Namely, define a hotkey on the Discard pile using the “Include command to send entire deck to another deck” tickbox. Then on the Draw pile, specify that hotkey in the “Send hotkey when empty?” option.

So you have buttons to draw cards into player hands or draw cards into the discard as needed, but whenever the draw pile empties, it automatically fires the hotkey to return everything in the discard to the draw pile. I tested it just now and it seems to be ok.

You made mention of the Reshuffle function. It’s there if you want that option, but really it comes down to whether or not the ordering of cards in your draw pile is important to retain. If you don’t care about card ordering, you could use Reshuffle: Always, which means any time something is taken it’s a random selection of what’s there, i.e. it is not taking the “top card”. It depends on the rules of your game whether that’s acceptable or not.

I had considered that option, but I was thinking there might be situations where reshuffling after a draw empties the pile results in different cards going back in compared to reshuffling while trying to draw from an empty pile (other cards may have been played in the meantime).

I just need to figure out how to get a GKC from a window into the main module. It seems like I might be able to create an invisible piece in that window which takes in the GKC and puts out an actual global key command which reaches into the other windows. It’s just so bonkers that a thing called ‘global’ only works on the window it’s in.