Beanshell puzzler

I’m trying to use Count{} in a Restricted Command expression but i’m getting this error.
Any one got any pointers for where I’m going wrong or things I can try?

  • Bad Data in Module: Expression evaluation error Expression={Count("{CurrentX==$CurrentX$ && CurrentY==$CurrentY$ && can_garrison==true}",“Main Map”)==0 && maintenance==false}, Error=Method Invocation _interp.count

What you have done looks good.

There was an issue in this area vassalengine.org/tracker/sho … i?id=13291 but it should have been fixed in version 3.4.0.

However, a quick debug session shows me something whacko is going on. I have opened a new bug report and will investigate.

Thanks Brent; appreciate the update. I can stop tearing my hair out… which is just as well.

V3.4.8 appears to fix the problem that I was having, with one exception; I am seeing the same error messages as before but only generated from pieces that have been placed via the Replace Marker trait - i.e. the first action taken to do such a replace, generates the messages shown below:

[code]- Bad Data in Module: Expression evaluation error Expression={Count("{LocationName=="$LocationName$" && Type==“Garrison”}",“Main Map”)>0}, Error=Method Invocation _interp.count

  • Bad Data in Module: Expression evaluation error Expression={Count("{CurrentX==$CurrentX$ && CurrentY==$CurrentY$ && can_garrison==true}",“Main Map”)==0 && maintenance==false}, Error=Method Invocation _interp.count[/code]

However, the functionality that these expressions supports still operates, even on the Replacement pieces. This was not the case before.

Is this some kind of Refresh Counters issue that I am seeing here?

Mark

Update on this post…

This issues I’ve been having seem to narrow down to how the Restrict Command trait handles, or doesn’t handle, beanshell, for which bug 14379 is logged.

Following this through, I think I now have a workaround, which is to take the BeanShell expression out of the Restrict Command and substitute that with a Dynamic Property. Simply set the dynamic property using the same Key Command(s) that you wish to restrict and position that below the Restrict Command in the trait order.

Correction - a Dynamic Property is not going to work. Hopefully, a Calculated Property will.