Drawing cards from an empty deck

I created a button to draw a card which pulls from the main deck and adds to the current deck. The button works until the the main deck is empty. I can then click on my current deck and issue a reshuffle (send cards to main deck). I was trying to figure out if I could create a trigger such that if I click the draw a card button, the trigger would fire and check to see if the main deck has zero cards, in which case, do the reshuffle. But I think the context of the trigger is not smart enough? I put the trigger on the button, but maybe it doesn’t understand that the command is for the current deck?

What exactly does your Trigger Action do?

You really have not explained what is not working.

I have an action button that performs a command called DrawSHL
There is a GKC for DrawSHL that does a SendSHL to the main deck.
The main deck maps SendSHL to Send to Location to send a card to the draw pile.
The draw pile has keyword “ReshuffleSHL” that sends the entire deck back to the main deck.
I have added a trigger to the button that checks to see if DrawSHL was invoked and the deck is empty. If so, issue the ReshuffleSHL:

But when I run it, nothing happens. Right-clicking on the button and choosing trigger does nothing either.

Without the benefit of seeing all the configs in question, my preliminary conclusion is that you’re missing that GKCs can only be received by pieces, not game components (e.g., decks). So the ReshuffleSHL named command you’re sending must be sent out by a Global Hotkey, not a GKC.

This is the draw deck that has the reshuffle hotkey:

I can right-click on this deck and choose reshuffle and it works. Can I invoke this same function through a trigger?

In the prior image, your Trigger is invoking a ReshuffleSHL named command. That alone cannot cause the identically-named command shown in the deck’s config to execute. What it’ll do is look within the piece where the Trigger is executing and see if there’s a trait defined that will perform ReshuffleSHL, and it looks like you have none.

To get a piece to invoke a command on a game component, you need to add a Global Hotkey trait to the piece. The GH should work if you set it up as Key command: ReshuffleSHL (this is what will make the Trigger cause the GH to execute) and Global Hotkey: ReshuffleSHL (now you’re sending that same named command out into the void that game components (not pieces) will respond to, presumably the deck now will.

We’re getting closer. Where am I adding this Global Hotkey @JoelCFC25 ?
I tried it on the the action button pictured above and then the button stopped working.
I tried adding it to the card prototype and nothing happened.

I understood your process to be initiated by clicking the button you’ve designed, so my prior image is meant to suggest adding the Global Hotkey to the list of traits on that button piece, as indicated by the red arrow. A Global Hotkey in your cards themselves won’t do anything unless you have other logic in them to activate it.

Thanks @JoelCFC25 but when I put it on the piece, the button no longer functions. I click on it and nothing happens. I have tried the GH in every trait position in case that made a difference, but still no luck. Here is what it looks like:

I’m probably not helping by suggesting anything further. If you’re able to share a cloud storage link to your work in progress, I’d look at it (along with precise instructions on where to look if it’s not obvious).

Are your decks in different map windows?

@shilinski Yes, there is a map with the drawn cards deck and another map with the main deck.

The number of pieces in a deck is a map level property. Buttons or any components in a **different ** map won’t see that property. It would be undefined. This could be part of your problem.

@shilinski the expression builder let me pick that so I assumed it was valid. Is there no way to get the property of the deck on the other map?

Not easily. You’d either have to detect that the deck was empty in a different way, or you’d have to define a module global property and have a piece on that map copy the number of cards to it. Or I suppose you could have a proxy piece on that map, who could see the number of cards, do all the work for you. And even then, I don’t know if that’s your only problem.

Okay, I am very close now. Here is the trigger function:
{GetMapProperty(“SHL Deck_numPieces”,“Setup”)==0}
This allows me to get the count on another map. Fancy!
Here is the problem: when there is 1 card left in the deck and I click draw, the card is drawn and the trigger says the other deck is empty and reshuffles it, so I never get to see the last card drawn. I want it so the trigger happens if I click draw and there is nothing left to begin with. Hmm.
@shilinski @JoelCFC25

That should just be a matter of using a Trigger Action to make certain that the check for an empty deck occurs before drawing the card, and not after. In other words, don’t trigger your current Trigger Action and your Global Key Command from the same Key Command; add a new Trigger Action that’s triggered by the Action Button, and have that Trigger Action first call the existing Trigger Action (to check if the deck is empty and reshuffle if necessary), and then call the Draw Card GKC.

Well done. I would have never thought of using GetProperty that way.

Success! Here is what I had to do:
Action Button calls DrawClick

Trigger looking for DrawClick does two things…

called trigger looking for ReshuffleCheck

sent DrawSHL to draw a card

And finally there is a Global Hotkey to so that the ReshuffleSHL trigger can find the reshuffle hotkey on the deck:

Thanks to everyone who jumped in to get this working! :+1: