Problem with LocationName


I noticed some strange behavior involving LocationName in a hex grid, which only shows up in the case where the hex code starts with a 0, like 0502.
The condition Prop = $ LocationName $, where Prop is the name of a dynamic or global property, returns the value 502 and not 0502, which results in errors in executing commands.

Is it possible to solve this problem in a simple way?


Panther 2010


I’m wondering if writing your expression as Prop = “$ LocationName $” will solve the problem. I’m thinking that since the location name is composed of numerals, the value is interpreted as numeric rather than as a string of characters.

I believe {Prop == LocationName.format("%04d")} should also work…this tells Java/Beanshell to format the string as a decimal, left-padded with zeros to a length of 4.

I recall that this is what worked for me when I had a similar problem, using beanshell to test LocationName==$LocationName$ in a Count() function.

Thanks to everyone who responded to my request.

In the meantime, I solved the problem, albeit in a somewhat artificial way.

I noticed by chance that while LocationName is a string variable, when loading the contents of that variable of another variable, for example: CurrentHex = $ LocationName $, where CurrentHex is a global variable, even not defined as numeric, Vassal transforms the string into a number: if the LocationName value is the string “0703”, CurrentHex has the numeric value 703.

Not sure if this is a bug or a Vassal feature.

In any case, it was sufficient to insert the condition: CurrentHex / 1000 = 0 in a trigger, in order to then be able to manage separately all the cases in which the first character of the string contained in LocationName is a zero.

I also tried the solution proposed by Jrwatts, which looked very promising, but I get “expression evalutation error”.

Panther 2010

Drat. I was hoping the format method was implemented in Beanshell, but I hadn’t actually tried it myself. Guess not.

Did you try {Prop == “$LocationName$”}? I can’t think of any reason why that wouldn’t work.

Hello Jrwatts,

I use a Set Global Property to load the string value of LocationName into the Global Property CurrentHex.

If LocationName = “0708”, this is what happens :

Global Property Name : CurrentHex (it is not numeric)
Key Command : GETPOS
Type : Set Valued Directly

If in the Prompt I write {LocationName}, the value of CurrentHex is the number 708;

If in the Prompt I write {LocationName.format("%04d")}, I get Expression Evalutation Error (LocationName.format("%04d").

Any suggestion?

Be well.


Panther 2010

Possibly {"$LocationName$"} might work.


It works!!

Thank you a lot!

This problem has haunted me for years.


Panther 2010