Looking for a function

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

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?

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

{ 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

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?

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).

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 ?

OK, so you need a Global Key Command probably on the map, that addresses the HQ units and then sends the command specified in Layer 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, 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

    {BasicName.endswith("HQ")}
    
  • You can also define a property in the piece ( Prototype) that sets a particular property to some fixed value. This can be done via a Marker trait:

    You can then select those pieces with the expression

    {HQ == true}
    

In summary

  • Global Key Command
    • 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
  • Name: HQ
  • Marker
    • Name: HQ
    • Value: true
  • …

And

  • Piece
    • Name: 1st battalion HQ
    • Prototype
      • Name: HQ
    • Layer
      • Images: [...]
      • Names: [...]
      • Reset to level: resetToFront
      • Reset to level number: 1 or whatever matches the front image
      • …
    • …

See this page.

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

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 ?