Using Substring for a Comparaison

I am using a Global Key Command to send a card from a Deck to a Start Stack on a specific Map Window. The Map Window is named Player 1’s Hand. I am using the .substring(X,Y) function to return the “Player 1” substring, which I use in the follwing expression.

image

The expression doesn’t work. I know that the substring function returns “Player 1 Deck”, having tested it in a Report Action. And, if I use

{DeckName=="Player 1 Deck"}

the expression works. What am I missing?

Hello, I think Current Map should not be in “quotes”

Is this an extra “)” ?

image

If I’m right, Vassal will generate a bad data error but you might have missed that. Also, the Expression Builder would show a red X - try pressing the calculation icon next to the expression.
Before:


After removing the trailing “)”:

In fact, you do need the quotes around CurrentMap. However, you don’t actually need GetProperty() at all here. You could try this:
{DeckName == CurrentMap.substring(0,8) + " Deck"}

I think that will do what you intended, but instead of using the Additional Expression field, why not use Pre-select? Like this:

One more thing - the expression can be simplified further by configuring a Global Property on each of the maps that are link to a deck.

Suppose you define a Global Property called “handSide” on each of these maps. For example on the map starting “Player 1”,

Now, you can modify the card drawing GKC to use a very simple legacy expression (i.e no curly braces):

This technique is especially useful if you want to use the map’s owner - in the example, the handSide property - elsewhere.

This first solution did not work, even though the Expression Builder shows a green check mark and when using the same Expression in a Report Action generates the correct string: Player 1 Deck.

This solution did work.

This solution is even more elegant, but I am afraid of the legacy part if it ever disappers in a future version (4.0) of VASSAL.

I have had issues getting a GKC to recognise CurrentMap, but I wouldn’t have expected it in the additional matching expression, as that is evaluated on the piece. Curious but at least the Pre-Select solution is working.

I’m not so concerned but you could equally use {handSide + " Deck"}

1 Like