Regular and Beanshell (& building a complex Expression for Newbies)

Hello Brent;
This is awesome! I tried to utilise a CP before but the module examples I found were too complex and I could not make any sense of them so didn’t know where to start. I will see what I can do with this CP now thanks to you.

A couple of questions if you don’t mind;

  1. Does this mean to use the CP result outside the Piece I make a GP with the same name as the CP so it can be referenced elsewhere…or is there more to it?
  1. Out of curiosity, if I was to use this Expression in a Dynamic Property here (not this one though)…

    …would this also work albeit manually? I read on here that CPs can slow things down if too many are used.

You are right of course. I didn’t intend to have so much in this module (just the Base game) when I started so wasn’t too worried. I use Photoshop Elements 2020 which can compress files like that to around 500kb or so and will do it when I get some of these things working properly. Never heard of optipng before but will try that also.

Now this…

…is my fault and I apologise for forgetting this in the instructions :flushed:. The Trigger needs to work when the second layer which says “Fighter Continues -1” is placed on the fighter Piece so unless there is something I don’t know it should be 2.

And finally…

…this is a good idea I think I know how to do that.

This info is fantastic and will give me something to chew on for a while. This was becoming very frustrating. :+1:

Regards;
Darren

Hi Darren,

I think your main problem is a lack of understanding on some of the basic concepts and how the different components and traits work together.

As part of my 3.7 development work, I am writing an additional Concepts page and another Intro Beanshell page for Reference guide, partly spurred on by your troubles. That’s a bit off though.

Now, for your questions:

Making a GP of the same name will have no effect. Each individual Property is complete unique and unrelated. When you reference a property named ‘X’ in a piece trait, the following happens to find a value for that property. The first find of a value of property ‘X’ is used as the value:

  1. Search each trait in the current piece to see if any of the traits has a value for property ‘X’. The traits are searched in reverse order (bottom up) of what they appear in the Piece Definer.

  2. If we reach the end of all the traits, then see if the piece is currently in a Zone on a Map. If so, see of the Zone has a Global property named X.

  3. Still not found, Check the Map the piece is on to see if it has a Global property named ‘X’.

  4. Still not found, then check if VASSAL knows what ‘X’ is. This might be a module level Global Property, or a system property.

So, a piece can directly ‘see’ and ‘read’ any property in itself, it’s current Zone, it’s current Map or in the top-level module.

It doesn’t work the other way. Nothing else can directly ‘see’ any property inside the piece, without using some of the new functions I am developing for v3.7.

The current work-around for reading a property inside a piece somewhere else is to create a GP (let’s say you create a module level GP ‘X2’), as you thought, but you need to then tell the piece (probably using a Global Key Command) to set the GP X2 to the value of X using a Set Global Property trait. Once complete, other components can then just reference the value X2, because every piece and every component can see module-level GP’s.

Organising the transfer of that value is the complicated part, using a Trigger Action in the piece to co-ordinate the actions required.

Yes, that should work and set the value of the expression into the specified CP. Again, You may (probably will) need a Trigger Action to fire off a sequence of Key Commands to run the steps you need in sequence.

Alternatively, you could set up exactly the same Key Command in a Set Global Property trait and set the value directly into a GP.

It depends what needs to ‘see’ the value next and use it.

Understanding and using Trigger Action to run a sequence of steps in order is the Key to more complex actions. Each trait provides small building block actions that need to be combined in order to do something useful.

Cheers!

1 Like

That would be extremely useful and possibly some sample modules using expressions? That way we can see how, when and where the expressions are used and what they can do. I don’t know about others but my biggest issue is not knowing where to start with them.

So here you can change the value of a global property from within a Piece using a Set Global Property Trait and that value can then be used in Expressions by any other Piece. Yes?

That is how I thought it worked except I was trying to make a Restrict Command Trait work on one of the Checkmarks in the Mission Log using the MissionChart GP in my module and the Layer it was set to. It wouldn’t work. I got around a similar problem before by using a different GP “Planview” which is on another board. Don’t know what the problem was but I found a way around it. The SGP for MissionChart and the Checkmark are located in the same Zone.

Oh! I had the idea that a Calculated Property wouldn’t be need in this case. The Expression would only run once when activated by whatever command is assigned to it in the Dynamic Property. This might be a little too complicated for now so I will leave it alone.

Well this information could keep me busy for a while. Thanks once again Brent.

Regards;
Darren

Yes, exactly. Any other pieces that can see that GP. If you set a Zone or Map level GP, then only pieces in that Zone of Map can see that particular GP. Module-level GP’s are visible to all, so most people just use GP’s for convenience for this sort of thing.

Oh! I had the idea that a Calculated Property wouldn’t be need in this case.

Sorry typo on my part, that was supposed to DP, not CP. No Calculated Property needed.

1 Like