# Looking for a function

**URL:** <https://forum.vassalengine.org/t/looking-for-a-function/90505>\
**Category:** Module Design\
**Created:** [September 9, 2026, 2:01am UTC](https://forum.vassalengine.org/t/looking-for-a-function/90505 "2026-09-09T02:01:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MadDog](https://forum.vassalengine.org/letter_avatar_proxy/v4/letter/m/a183cd/32.png) [@MadDog](https://forum.vassalengine.org/u/MadDog)\
**Post date:** [September 9, 2026, 2:01am UTC](https://forum.vassalengine.org/t/looking-for-a-function/90505/1 "2026-09-09T02:01:55Z")

</div>

I am working on a module for the BCS system. I am looking for a function that works like this:

Find all game pieces that are of a type “HQ”, then set all of their Layer Properties to Image 1 (i.e. the “front side”)

I have already defined “HQ” in the system, so I can find the right type of pieces, but I am struggling to find how to set all of them to the “front” sides. I think this is something in the Expression builder, but some of the expressions arent obvious.

I need something like an IF-THEN.

thanks,

Mad Dog

---

<div class="post-metadata">

**Author:** ![cholmcc](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/cholmcc/32/8319_2.png) [@cholmcc](https://forum.vassalengine.org/u/cholmcc)\
**Post date:** [September 9, 2026, 9:34am UTC](https://forum.vassalengine.org/t/looking-for-a-function/90505/2 "2026-09-09T09:34:51Z")

</div>

> [@MadDog](#):
>
> Find all game pieces that are of a type “HQ”, then set all of their Layer Properties to Image 1 (i.e. the “front side”)

The answer really depends on the context.

- From where does the request orignate? Is it from another counter, or from some toolbar/module/map component?
- Do you need to be able to modify the HQ’s layer in other ways?

> [@MadDog](#):
>
> I need something like an IF-THEN.

There’s no `if ... then ... else ....` possible in the expressions, because the expressions _must_ be simple statements that evaluate to a value. However, one can use the tenary statement

```auto
{ condition ? then-value : else-value }

```

where `condition` evaluates to a boolean value, and `then-value` is the value if `condition` is `true` and `then-value` is the value if the `condition` is `false`

Yours,  
_Christian_

---

<div class="post-metadata">

**Author:** ![Benkyo](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/benkyo/32/3289_2.png) [@Benkyo](https://forum.vassalengine.org/u/Benkyo)\
**Post date:** [September 9, 2026, 9:43am UTC](https://forum.vassalengine.org/t/looking-for-a-function/90505/3 "2026-09-09T09:43:19Z")

</div>

It sounds like a very simple problem, so maybe I am missing something.

But if you have a global key command that filters for “HQ” pieces, and the HQ pieces have a Layer trait with a key command matching the gkc that switches to Image 1, isn’t that all you need?

---

<div class="post-metadata">

**Author:** ![JoelCFC25](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/joelcfc25/32/2687_2.png) [@JoelCFC25](https://forum.vassalengine.org/u/JoelCFC25)\
**Post date:** [September 9, 2026, 12:49pm UTC](https://forum.vassalengine.org/t/looking-for-a-function/90505/4 "2026-09-09T12:49:43Z")

</div>

For most experienced editors, agree that this would be pretty straightforward–but I’d guess the OP is relatively new. If that’s true, maybe the utility of a Global Key Command is not fully understood, nor (as stated earlier) the two ways of originating one. Also, perhaps the Layer traits at issue on the HQ pieces haven’t been configured with a “Reset to level” key command (I see this frequently, many modules with two-step counters only have a single command to increase the Layer level and have loop through levels turned on, in effect a single command that acts like a toggle).

---

<div class="post-metadata">

**Author:** ![MadDog](https://forum.vassalengine.org/letter_avatar_proxy/v4/letter/m/a183cd/32.png) [@MadDog](https://forum.vassalengine.org/u/MadDog)\
**Post date:** [September 9, 2026, 11:31pm UTC](https://forum.vassalengine.org/t/looking-for-a-function/90505/5 "2026-09-09T23:31:03Z")

</div>

Indeed, I can understand what the different functions are supposed to do (in similar modules), but for reasons I am still trying to figure out , dont work for me in my module. Sort of like a dog looking at a shiny watch. Some of the logical operators are unknown to me (I get “==”, but what is “&&” ? AND ?)

cholmcc: there is a button on the toolbar that the user pushes, in order to “reset all HQ”

Benkyo: I think you see what I need.

This should be possible, even at my level of expertise, as “HQ” is a prototype definition, and so are the layers in HQ pieces.

So, to sum it up: User presses GKC “Reset all HQ”. This locates all pieces identified in the prototypes as “HQ”, then sets the Layer to Image 1 (i.e., the “front” side).

In the expression builder this is a Property–\>Piece Property–\>Layer, Counter Side–\> Counterside Image… ?

Its a testament to the Vassal front end that a non-programmer can even get this far. In many cases I can go through trial and error with single changes and see how things work, or Import/Export XML files, and things usually work out.

thanks,

Mad Dog

Edit: Joel - it took me a minute to fully grasp what you were saying…“Reset to Level” in the Layers Property ! [Facepalm] I didnt notice that before. So, all I have to do GKC-find all HQ, then Reset to Level 1 ?

---

<div class="post-metadata">

**Author:** ![cholmcc](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/cholmcc/32/8319_2.png) [@cholmcc](https://forum.vassalengine.org/u/cholmcc)\
**Post date:** [September 10, 2026, 7:36am UTC](https://forum.vassalengine.org/t/looking-for-a-function/90505/6 "2026-09-10T07:36:53Z")

</div>

> [@MadDog](#):
>
> cholmcc: there is a button on the toolbar that the user pushes, in order to “reset all HQ”

OK, so you need a [Global Key Command](https://vassalengine.org/doc/latest/ReferenceManual/GlobalKeyCommands.html#top) probably on the map, that addresses the HQ units and then sends the command specified in [Layer](https://vassalengine.org/doc/latest/ReferenceManual/Layer.html#top) for _Reset to level_.

To address the pieces, you must somehow match the pieces via an expression. You cannot match on pieces that contains a particular [Prototype](https://vassalengine.org/doc/latest/ReferenceManual/Prototypes.html#top), because once a piece is in play, its prototypes are fully unrolled. That means that Vassal has no idea about which prototypes were included in a piece to define it.

There are other ways to match pieces:

- You can match on the name, for example if all HQ piece’s name end in `HQ`, you can see if a piece’s `BasicName` property ends in `"HQ"` with

- You can also define a property in the piece ( [Prototype](https://vassalengine.org/doc/latest/ReferenceManual/Prototypes.html#top)) that sets a particular property to some fixed value. This can be done via a [Marker](https://vassalengine.org/doc/latest/ReferenceManual/PropertyMarker.html#top) trait:

In summary

- [Global Key Command](https://vassalengine.org/doc/latest/ReferenceManual/GlobalKeyCommands.html#top)
  - Button text: `Reset HQs`
  - Button key: `Ctrl+R`
  - Key: `resetToFront`
  - Fast select:
    - By property: `true`
      - Name: `HQ`
      - Comparison: `==`
      - Value: `true`

  - Single map: `true`_if_ the Global Key Command is in the map hierarchy

- [Prototype](https://vassalengine.org/doc/latest/ReferenceManual/Prototypes.html#top)
- Name: `HQ`
- [Marker](https://vassalengine.org/doc/latest/ReferenceManual/PropertyMarker.html#top)
  - Name: `HQ`
  - Value: `true`

- …

And

- Piece
  - Name: 1st battalion HQ
  - [Prototype](https://vassalengine.org/doc/latest/ReferenceManual/UsePrototype.html#top)
    - Name: `HQ`

  - [Layer](https://vassalengine.org/doc/latest/ReferenceManual/Layer.html#top)
    - Images: `[...]`
    - Names: `[...]`
    - Reset to level: `resetToFront`
    - Reset to level number: `1` _or_ whatever matches the front image
    - …

  - …

> [@MadDog](#):
>
> Some of the logical operators are unknown to me (I get “==”, but what is “&&” ? AND ?)

See [this page](https://vassalengine.org/doc/latest/ReferenceManual/Expression.html).

Remember to tick off the solution to your problem. That helps others find the solution to their problems. Only you as OP can do that.

Yours,  
_Christian_

---

<div class="post-metadata">

**Author:** ![MadDog](https://forum.vassalengine.org/letter_avatar_proxy/v4/letter/m/a183cd/32.png) [@MadDog](https://forum.vassalengine.org/u/MadDog)\
**Post date:** [September 11, 2026, 1:44am UTC](https://forum.vassalengine.org/t/looking-for-a-function/90505/7 "2026-09-11T01:44:17Z")

</div>

Once Joel pointed out the reset to level was in the Layers Prototype, I got to work, and it was that easy. Cholmcc then added further information and now it makes sense to me. As a bonus, it allowed to find my error in a related function.

I used a global key command that when the user hits the toolbar button, identifies all the pieces with the HQ descriptor (“UnitType==HQ”), then reset to Layer Properties to level 1 (“front side”) upon the Key command of Ctrl+R.

So, thanks to everyone, this has solved the issue.

Cholmcc: you mean describe how I solved it, or is there a flag I set on this thread ?
