How to make layer visible on mouse selection?

Hi,
I want to make a Layer visible/triggered on the moment a piece is selected. So, if a piece is selected show level 2, if not level 1(empty). It should be possible by using “Selected” Basic Piece trait, but no success so far.
It works for a “Text label” - topic here: Text label triggered on selection

Created a layer that is always active and wanted levels to follow an expression of a Dynamic Property.
I was trying to combine it with a Trigger Action Trait, but it will not work because, (as per designer guide) Trigger Action Trait cannot passively ʻlistenʼ for matching Properties and then fire automatically.

Any ideas?

You could add an Action Button to the piece, that would give you a key command that fires whenever the piece is clicked.

On second thought, that would work for when you selected the piece, but not when you unselected it.

Okay, second idea–set the layer to follow an expression, make the expression a Calculated Property that is simply Selected ? 2 : 1 (assuming layer 1 is the unselected state and layer 2 is the selected state).

@jrwatts Thank you!
Damn, that was so simple. I completely overlooked that this function is already pre-built.
Selected ? 2 : 1 works like a charm.

Just be aware that using Calculated Properties in Layer-follow expressions is very ‘expensive’. They can be re-evaluated many times a second. It’s fine for a counter or two, but if you have large numbers of pieces doing this, you will start to see a significant degradation in general performance and responsiveness.

1 Like

@Brent_Easton Thank you for this hint. This is probably exactly what will happen;)
Speaking of evaluation speed, which is faster?
1)Layers with graphics (e.g. name\stats on a counter) individual to each one of hundred game pieces
Or
2)Individual names made via “Game Piece Layout” in “GP Image Definitions”

No difference between those two, if there is no calculation required to determine which image to display, then there is no overhead, so whichever is most convenient for you.

The problem with the Layer-follow expressions is that each time Vassal redraws a piece (which can happen many times a second if that piece is the centre of ‘activity’ (e.g. doing stuff with the mouse) ), the expression has to be re-evaluated which is one of the slowest parts of Vassal. Multiply that by 100 pieces and you have problems.