I am working on a module where I want to have the ability to send a card from a deck to a generic piece. I know how to send a card to a specific piece (through property matching), but is it possible to send a card to a generic piece?
Here is how I envision this working:
Right-click generic piece, select ‘Draw Card’
Card gets drawn from deck and sent to the selected generic piece.
There is a slicker way to do this now without needing a global property. Inside the card prototype, you define a dynamic property, say “target.” It replaces the global property. You can leave the initial value blank.
in the sender piece, define a unique marker, e,g sender = “blah blah”. You issue a GKC to the cards. At the bottom of the GKC you can now set dynamic properties in the recipient card, so you enter target= {“$sender$”}. This loads “blah blah” into the card’s dynamic property “target” just before it services the GKC. The card does send-to another piece with property sender=$target$.
The great thing about this you don’t need global properties. The communication is strictly private between sender and recipient. And it’s like making a function call—with arguments!
by property: Property: DeckName, comparison: ==, value: PieceDeck
(Note, if the deck to draw from depends on some property in the originating piece, - e.g., for piece with property Side you need to draw from deck Side+"Deck", then you can put an expression for value - evaluated at the source piece, e.g., {Side+"Deck"}).
Within a Deck, apply to: Fixed number of pieces, number of pieces: {1}
Then, you have a prototype, say PieceCard, which is included in all your card pieces with traits
You initiate the Trigger Action by the key requestCard in the piece (It could be through a short-cut, context-menu, or some other means).
The piece sets the Dynamic PropertyWhoWantsACard to "Me" by the command IWantACard
The piece sends the key Gimme to it self which issues the Global Key CommandGoToPiece to the top card in the deck PieceDeck (or what ever the deck is called).
The top card receives the Send to Location command GoToPiece, which then looks for a piece with the property WhoWantsACard set to "Me" (the piece that originated the command), and places the card piece at the location of that piece.
Back in the piece, the piece issues GotIt to itself which sets the Dynamic PropertyWhoWantsACard to "NoOne".
I think that should work and be fairly optimised for execution. Hopefully it is a little clearer what you need to do.
I’ve included a dropbox link to a small module. It contains a deck of cards and 3 buttons. Press a button, and it gets a card, which is placed atop the button. Each button has a marker called “slot”, which contains a unique value just for that button. When you press a button, the button sends a GKC to one card in the deck. As it does this, it also loads its “slot” into a dynamic property inside the card. The card uses that unique identity to go to the button.
You can also try this one - which follows the strategy I outlined above. In this module, the pieces do not need a unique identifier, and everything is handled in the prototype. Can be a bit easier to maintain.
I will remove the module at some point in the future.
Note, both Stan’s (@ shilinski) I my approach requires that Vassal queries all possible pieces that has a property with the appropriate value, so in terms of performance, I think they are equivalent.
@uckelman Would it make sense to have a project in the module library where one could post such example modules? I appreciate that it will take up some storage on the hosting service, and there’s a consideration around who will be the project owner(s). Of course, if we can remove modules, then we could enforce some sort of clean-up on such a project. I think it could be a neat way for us to share solutions to problems.