Problem with LocationName

Hello,

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?

Thanks.

Panther 2010

:frowning:

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.

:question:

Panther 2010

Possibly {"$LocationName$"} might work.

Great!!

It works!!

Thank you a lot!

This problem has haunted me for years.

+++++++1!

Panther 2010

:laughing: