Page 1 of 1

Comparing Properties Between Game Pieces

PostPosted: July 25th, 2018, 3:10 pm
by twenck
I need to have a piece issue a GKC to other pieces that have a matching property.

The Module Designer's Guide has an example in which a counter has a GKC command with matching properties that includes "nation = $nation$".

This works correctly, comparing the property nation on the counter receiving the GKC, to the property $nation$ on the counter sending the GKC.

I need to make a more complex set of comparisons and therefore need to use a Beanshell Expression. I cannot come up with any method to compare property values between two pieces in a Beanshell Expression. I tried:

{nation = $nation$}
{nation = "$nation$}
etc.

Can anyone advise how to compare property values between two pieces using a Beanshell Expression?


Thank you,

Tom

Re: Comparing Properties Between Game Pieces

PostPosted: July 27th, 2018, 5:59 pm
by DrNostromo
Off the top of my head, I believe it would just be

{nation==nation}

The use of $ (dollar signs) to signify variables is a Vassal tool that is not recognized by beanshell but, if you use that syntax, clicking the Expression Builder button should convert Vassal syntax to a Beanshell compatible expression.

Re: Comparing Properties Between Game Pieces

PostPosted: July 28th, 2018, 9:56 pm
by Malnorma
It seems unlikely that the same name would correctly refer to different objects without any kind of qualifier though.

Re: Comparing Properties Between Game Pieces

PostPosted: September 2nd, 2018, 4:28 pm
by twenck
Malnorma is correct.

Even though converting nation=$nation$ by clicking on the Expression Builder button does yield {nation==nation},

{nation==nation} is always true because they do NOT refer to different objects -- this compares nation to itself.

Anyone have a solution? I do need to compare properties between two different game pieces using beanshell.

Re: Comparing Properties Between Game Pieces

PostPosted: September 3rd, 2018, 12:47 am
by Brent Easton
Comparing properties between two pieces is a bit tricky in Beanshell expressions. The old-style expressions had special coding which handled each side of the == differently.

As far as I can remember, you should be able to use $...$ inside a beanshell expression to force it to be evaluated on the source piece before being tested against the destination piece:

{nation=="$nation$"}

You original example above would have failed due to using = instead of == and no closing " (though that may be just typos when you where writing it up).

Regards,
Brent.