v.3.3.2--$LocationName$ based CalculatedProperty => error

Download module: dropbox.com/s/x03crb0bke5t1 … .vmod?dl=0

To replicate:

  1. Make a board with irregular zone grid. Set the reported name to $gridLocation$.

  2. Define a calculated property value of which is calculated as follows:

If($CurrentZone$=="RedZone",$LocationName$-300,"n/a")
  1. Add a TextLabel that displays this property.

  2. Move counter of RedZone. An error shows up:

Bad Data in Module: Expression evaluation error counter-Calculated Property[value]={If($CurrentZone$=="RedZone",$LocationName$-300,"n/a")}, Error= inline evaluation of: ``_xyzzy=_plugh();'' internal Error: Unimplemented binary String operator

BTW: it is not only TextLabel that breakes the module. If I use any other trait that refers to that calculated property in any way (like setting Global Property to this value), the error shows up too.

I’d have to review all the BeanShell threads where changes are being made, but I don’t think you would ever want $CurrentZone$ on the lefthand side of ==.

Surely it should just be CurrentZone (not surrounded by $)?

Thank you for the answer but neither removal of $ nor changing sides (“RedZone”==CurrentZone) didn’t help.

I would suggest using the following:

CurrentZone==“RedZone” ? Integer.parseInt(LocationName) - 300 : “n/a”

Let me know how that works out.

The problem is that as previously reported, anissue with the If() beanshell function is that all parts of the If statement are evaluated, regardless of whether or not the initial test is true.

This is not only inefficient, but generates errors like this when they should not occur.

The solution is to replace the usage of the If() function with the equivalent ? : statement.

CurrentZone==“RedZone” ? LocationName - 300 : “n/a”

Should be sufficient. Strings can be added to numbers as long as it looks like a number.

Yes, this helped, thanks a lot. Nonetheless, evaluating instructions that are behind a false condition sounds like a kind of blasphemy, programming-wise… :open_mouth:

Well yes, which is why we now promote ? : as the preferred solution. The fact that the If() function does that was an unavoidable side-effect of the way it was implemented, it can’t be fixed. All we can do is recommend that people no longer user it.