A couple of methods come to mind. I mentioned (2 below) “Levels follow expression value”, which I prefer myself but (1) may be more familiar as it uses Key Commands on the Layer trait, which is the default when you add that trait to a piece.
Caveat
If you are using <layer_name>_
properties in the module then be cautious of changing such a layer for display purposes. You should review how you use those properties and adapt this method or other part of your module accordingly. See bottom of the Layer documentation page about these properties.
1) Toggling Layer display by using the layer Activate Key Command.
The Layer trait provides an Action option to Activate / Deactivate a layer. You need to uncheck “Always active?” to see this. In the following example, I’ve assumed that you don’t want players to see the Activate command on the pieces.
On re-activating the Level is restored to what it was before.
The effect on de-activating a Layer on <layer_name>_
properties is that <layer_name>_Active
becomes false and <layer_name>_Level
is set to the negative of the Level. The other properties become blank.
I am pretty sure that a layer is Active by default; so we just need to provide that toggle button. This would be a Global Key Command that finds all the pieces that you want to toggle layers on. For example, this Map GKC would find all the pieces with an experience layer on the map and give them the activate command shown on the previous example;
You could generalise this to send the toggleDisplay command to more pieces, if some pieces don’t have the experience layer. You just need to have some criteria like a Marker on all pieces that you wish to send the GKC to. The Hotkey is optional; in this example pressing F6 is an alternative to clicking on the button.
2) Toggling layer display by using Levels follow Expression Values field
This method that doesn’t require GKCs and may be quicker. It is a little more fiddly to set up if you are not already using it to determine the Layer levels. Another advantage is that it is possible to use this method in combination with Global Option preferences such that displaying the layers becomes player-specific (just like Game Piece Layers is).
If you have not used this field before, then you will need to start by moving your current layer setting method from Key Commands in the Layer trait into a Dynamic Property that sets the Layer Level. The Dynamic Property then goes into the “Levels follow expression value” field. Typically such layers are always active (we’ll be adding a blank layer anyway, if you currently have the layer sometimes inactive.
Here is an example DP setup to replace the Layer controls in the previous example. Notice that the minimum and maximum are set to mirror the available layers that you wish to display.
Here is what the Layer trait looks like, notice I’ve added a 5th blank layer. That is not set by the DP in the example, but we’ll use it in the next step.
How to apply a toggle button when using “Levels follow Expression Values”: this can be done using a Global Property with a Change-Property attribute added to it, that itself it controlled by a Button and/or Hotkey. If that GP is called “LayersOn” then the example expression should look like this:
{LayersOn ? experienceSetting: 5}
The Global Property would be defined at Map level (or could be Module level if you have multiple maps to which this function will apply).
Add a Change-Property attribute to the GP that looks like this:
The “!” before LayersOn in the New Value field simply toggles the value from true to false and back, so toggling the expression in the Layer trait between the blank image and the display image.
Providing Layer display as a per-user option.
To achieve this, replace the Global Property with a Global Option checkbox property. You can still control this by a button and/or hotkey but it requires using a control piece and a Global Key Command to perform the toggle. For more information see this tutorial.
Hope this helps. Feel free to ask questions or point out errors.