Uniform Card Deal Offset

I’m hesitant to post this question because I’m sure it’s been addressed many times, but after searching the forums for a while I wasn’t able to find a close enough post.

I have succeeded in delivering a card from my deck of playing cards (on a separate Private window) to the main window. It’s Sending to a irregular grid region. I was able to use beanshell math expressions in the Send To Location’s advanced/offset feature to yield random x-offsets (which looks great for dealing facedown cards to player’s regions) but I would like to also figure out how to have uniform x-offsets so for certain Send-To-Locations, the cards land in a clean, readable way.

My desire to keep the “messy” random x-offsets for some Send-To-Locations and “uniform” x-offsets for others on the same map makes me think that some solutions won’t be applicable here.

Any suggestions from the helpful Vassal Community?
Thanks.

For stuff like this, I create a numeric Global Property that possibly loops called $Offset$ or $Side_Offset$ for each player. For Poker, I’d set the range from 0 to 5. Each time a card is dealt, increment $Offset$ by 1 using Set Global Property. Either allow it to loop back to 0 or reset it to zero each round/turn (depends on the game rules). Use it as a multiplier in the Beanshell formula for the x offset. So if my cards are 100 pixels wide, I’d probably go with {$Offset$*120} to create some reasonable spacing between cards. In most cases, the y-coordinate is fixed.

Also, $ isn’t used in Beanshell. I’m just using it here to signify it is a property…

Thanks for this, m3tan!

I’ve been able to use your suggestion and get the cards to arrive at a specified distance as many times as there in the range of values, and then loop back to 0, 1 etc.

My follow-up question is what options do I have for resetting that Global Property to zero?

You could put a “Set Global Property” trait into a piece, and within that trait hit the “New” button under Key Commands and give it a key command to “Set Value Directly” and put 0. Presumably you’d blank out the “Menu Command” field since you don’t want this appearing on any popup menus, and have the key command itself either be some keystroke or else a “named keystroke” like “SetOffsetToZero” or something. Then you can send the piece a Global Key Command of the keystroke to tell it to do this whenever you want, or add this trait to any piece that wants to be able to set it to zero and just activate it directly within the piece without needing a Global Key Command.

Thank you very much, Cattlesquat! I wonder - since I’m trying to apply this to a standard deck of playing cards - if this would end up either resetting the count with every dealt card, or still require a manual reset. [I’m trying to make this VERY user-friendly so my friends who “aren’t any good at computers” don’t have any problems :smiley: ]

One idea I just had that I would love your input on… I really just want the count of this Global Property to zero out whenever the target of the card being dealt off of the top of the deck changes. [ie. when a different Send To Location (on the Card Prototype) is used.] Is there any way to utilize this detail to reset the count?

Sure - you’d add a Global Property somewhere called “DealTarget” or something like that, and in your generic “Prototype” for all your Cards you’d have a trigger that responded to getting dealt somewhere (depending on how you’re dealing them, either in responding to the trigger that gets sent to them to have them Send-to-Location themselves somewhere, or if players are just dragging them off themselves, you could have them respond to a Map’s keystroke-to-apply-on-move). They’d respond with a series of Trigger traits by first checking if their new location is different from DealTarget, and if so they’d activate a Set Global Property trait for your dealing offset (zeroing it out, as described previously). And then whether or not they’d done that they’d definitely activate a Set Global Property trait for DealTarget, setting that to their new location (or Zone or whatever other state you’re using to determine dealing target). It’s a couple of steps and you’ll have a little “journey of learning” getting the Triggers to all interact properly, but it can all be done.

Thank you! I understand 65-70% of this, so that’s “enough to be dangerous.” I’ll give it a shot!