How to keep leading zeros in expression

I have an expression I’m using to generate a date in the format:

Dynamic Property: CurrentMonth
(($MONTH$ == “Jan-Feb”) ? “01” : ($CurrentMonth$))

However, this expression is returning “1” and not “01” (probably treating it as a number instead of a string).

What syntax options are available to get it to return “01”???

Just a guess, but I think your first match might be always failing? $MONTH$ never equals “Jan-Feb”, so it always returns $CurrentMonth$, which might have a value of 1?

A string “01” should remain “01”, AFAIK.

You’re also using a bizarre mix of old-style and Beanshell expressions: those $-signs are superfluous, and may actually be causing the expression to fail. (I’m assuming that expression is enclosed in curly braces {}; if not, then your problem is trying to use the ternary operator in an old-style expression, where it’s not supported–unless that’s actually a Calculated Property, not a Dynamic Property, in which case the curly braces are implied and shouldn’t be included.)

The logical test (match) is working fine…

The issue is that “01” in the expression is interpreted as the integer 1, and not the string “01”…

So a more general question would be how do you get an expression to recognize that you intend for a number to be a string and not an integer…

Why are you trying to do the year, month, and day as separate properties? If you just do all 3 in one property, you shouldn’t have to worry about leading zeros…

The alternative is to use Java string functions to pad the single character out to 2 when you assemble the final string, instead.

(So, to actually answer your question, “how do you get an expression to recognize that you intend for a number to be a string and not an integer”, the answer is: you can’t. VASSAL assumes anything that can be interpreted as an integer is an integer.)

1 Like

This is one of the problems I really hate. I’ve tried to solve it in several ways, but none worked.
If Vassal decides that the string “'01” is the integer 1 there is nothing you can do to force Vassal to treat “01” as a string.
IMHO this is a bug and I hope that in the near future this will corrected.



Vassal v3.6 includes GetString() as a beanshell function. I haven’t tried it in your context but maybe worth a shot.

example, try the beanshell expression {GetString("myProperty")} where myProperty is the name of a Property that contains “01”.

Hello marktb1961,

thank you for your suggestion, that I will try. The most annoying thing is that I cannot always use the Send to Location trait, since every hex starting with a “0” is not considered a valid location name. For instance, hex 1032 is accepted, but hex 0804 is not. At present I use a combination of two Moved Fixed Distance traits to simulate the Send to Location trait if hex name has a value lesser than 1000.
Before I forget, where I can find a documentation about the new features in version 3.6.x ? :upside_down_face:

I’ve tended to define my hex grids as Alpha + Numeric for that reason.

For an overview of v3.6, see the Release Notes under the Documentation icon image.

1 Like

Hi @panther_2010,

I think I have finally, finally nailed this.

I discovered that there where 2 places where Expressions where being created and I was only fixing one of them.

Could you please try the new ZeroStringsNew build. This does several things:

  1. It winds back all existing attempts to address this issue since version 3.6.5.
  2. It fixes the problem at the lowest level (in both places!), instead of trying to patch various higher level usages.
  3. It is opt-in via a Global Option. You have to turn this option on in order to use it. All existing modules will see V3.6.5 functionality.

You will need to open Global Options and turn this option on (Help update for Global options, Grid Numbering and Send to Location to come):




Hello Brent,

I’m using v. 3.6.7 of Vassal, but I don’t see the option “Store integers with leading zeroes as String internally” in the Global Options.

I will do the test as soon as I can find it.

Be well.



Hi @panther_2010,

Sorry, I should have been clearer. This change is in an unreleased build. These can be found at Builds of vassalengine/vassal. The ones you are looking for all commence with ‘VASSAL-3.6.8-SNAPSHOT-b4b7512-ZeroStringsNew-windows’ and there is one for each platform we support. e.g. VASSAL-3.6.8-SNAPSHOT-b4b7512-ZeroStringsNew-windows-x86_64.exe for Windows 64.

You will need to download the appropriate one manually, run it and do a custom install so you don’t blat your existing installs.


You may need to scroll through a few pages to find it, it was generated on the 17th June.


Hello Brent,
I finally find the time to make the test, that was successfull. All works perfectly, now!
Cross of Iron to you!