How to use LocationName.toString()

Sorry my thought invoked such further thoughts. Perhaps the real answer is for the developer to add in some string functions that put the leading 0 back when it is required? Only another thought bubble there.

String.format("%02d", x) is probably the simplest Java code to display x as a two-digit number, adding a leading zero if necessary. Unfortunately, I don’t think we can use String.format() in BeanShell (please, correct me if I’m wrong, @Brent_Easton). However, even if that worked, you couldn’t simply set up a Calculated Property to be String.format("%02d", myDynamicProperty) as VASSAL would see that it evaluates to an Integer and immediately drop the leading zero again when you tried to use it somewhere else, anyway. Now, if the CP was "Hex " + String.format("%02d", myDynamicProperty) (i.e., adding some text so the whole thing is no longer just an Integer), that might preserve the leading zero…

2 Likes

For my own experience of this issue, my solution was similar to that - I was able to set the GridLocation in the left-most dimension to be alpha. Resulting in LocationNames such as A01, B01 etc. Maybe a leading space would do as well, allowing the displayed value to conform to a game’s map appearance, where that is a requirement.

1 Like

There is one thing I have never been able to understand: why Vassal automatically converts the content of a property, dynamic or global, into an integer even when the property has not been defined as numeric. In my humble opinion, such a string-to-number conversion should only take place if the property is declared numeric while it should be considered a string otherwise. Thus 0702 +1 would become 703 if the property is declared numeric and would become 07021 if declared non-numeric. This would avoid all the problems generated by the forced conversion of Vassal from string to number.

1 Like

Hi,

I have put up another build VASSAL-3.6.7-SNAPSHOT-c8eec56-Leading_Zeros that will hopefully resolve this particular problem with the Set Dynamic Property trait.

Regards,
Brent.

2 Likes

Hello Brent,

it works!!!

Great!!

Finally those damned leading zeros will not be a problem any more.
In the test, I loaded the value of a destination hex via promt to the Dynamic property ABHEX and then moved the air unit to the Air Base using a Send to location trait. No more issues.

You are my hero! Congratulations!

Cheers.

Panther_2010

3 Likes

Thanks for testing. The fix will appear in 3.6.7.

2 Likes