How to use LocationName.toString()

I want to load the value of LocationName in a non-integer Global Propery. I tried LocationName.toString() but I always get an error. This is because I don’t know the correct syntax to use in the Bean Shell (I hate it…).
Someone can help me, please?

Panther_2010

:rage:

1 Like

Can you supply an example of what you’ve tried and the error ?

Here are two images of what happened while making a test.


I wonder if LocationName is null and if that would cause the error.

When you turned on the Audit Trait preference as the error message suggests, what was in the error log?

Hi Panther,

You appear to have stumbled on to a bug, I am investigating.

Regards,
Brent.

1 Like

Hello

Well. I made some other tests and here are the result.

  1. To marktb1961 : LocationName is not null; the report shows the correct value. I used location, too. By the way, what is the difference between them?

  2. To uckelman : I turned on the Audit Trait and this is the errorlog:

2022-03-30 09:45:05,761 [6340-main] INFO VASSAL.launch.StartUp - Starting
2022-03-30 09:45:05,784 [6340-main] INFO VASSAL.launch.StartUp - OS Windows 10 10.0 amd64
2022-03-30 09:45:05,784 [6340-main] INFO VASSAL.launch.StartUp - Java version 17.0.2
2022-03-30 09:45:05,784 [6340-main] INFO VASSAL.launch.StartUp - Java home C:\Program Files\VASSAL-3.6.5\jre
2022-03-30 09:45:05,784 [6340-main] INFO VASSAL.launch.StartUp - VASSAL version 3.6.5
2022-03-30 09:45:06,115 [6340-AWT-EventQueue-0] INFO VASSAL.launch.ModuleManager - Manager
2022-03-30 09:45:15,103 [6340-SwingWorker-pool-2-thread-1] INFO VASSAL.launch.AbstractLaunchAction - Loading module file C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 09:45:20,692 [6340-SwingWorker-pool-2-thread-1] INFO VASSAL.launch.TilingHandler - No images to tile.
2022-03-30 09:45:20,695 [6340-SwingWorker-pool-2-thread-1] INFO VASSAL.launch.AbstractLaunchAction - Loading module Legion
2022-03-30 09:45:20,747 [6340-SwingWorker-pool-2-thread-1] INFO VASSAL.tools.io.ProcessLauncher - launching C:\Program Files\VASSAL-3.6.5\jre\bin\java -Xms512M -Xmx512M -Duser.home=C:\Users\Ares -Duser.dir=C:\Program Files\VASSAL-3.6.5 -cp lib\Vengine.jar VASSAL.launch.Editor --edit – C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 09:45:22,698 [12380-main] INFO VASSAL.launch.StartUp - Starting
2022-03-30 09:45:22,713 [12380-main] INFO VASSAL.launch.StartUp - OS Windows 10 10.0 amd64
2022-03-30 09:45:22,713 [12380-main] INFO VASSAL.launch.StartUp - Java version 17.0.2
2022-03-30 09:45:22,713 [12380-main] INFO VASSAL.launch.StartUp - Java home C:\Program Files\VASSAL-3.6.5\jre
2022-03-30 09:45:22,713 [12380-main] INFO VASSAL.launch.StartUp - VASSAL version 3.6.5
2022-03-30 09:45:22,713 [12380-main] INFO VASSAL.launch.Launcher - Editor
2022-03-30 09:45:32,222 [12380-AWT-EventQueue-0] INFO VASSAL.build.GameModule - Legion version 1.0
2022-03-30 09:49:30,628 [12380-AWT-EventQueue-0] INFO VASSAL.tools.io.ProcessLauncher - launching C:\Program Files\VASSAL-3.6.5\jre\bin\java -classpath lib\Vengine.jar -Duser.dir=C:\Program Files\VASSAL-3.6.5 VASSAL.launch.ModuleManager --update-module C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 09:49:33,205 [12380-AWT-EventQueue-0] INFO VASSAL.build.GameModule - Exiting
2022-03-30 09:49:35,295 [6340-SwingWorker-pool-2-thread-2] INFO VASSAL.launch.AbstractLaunchAction - Loading module file C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 09:49:35,498 [6340-SwingWorker-pool-2-thread-2] INFO VASSAL.launch.TilingHandler - No images to tile.
2022-03-30 09:49:35,498 [6340-SwingWorker-pool-2-thread-2] INFO VASSAL.launch.AbstractLaunchAction - Loading module Legion
2022-03-30 09:49:35,498 [6340-SwingWorker-pool-2-thread-2] INFO VASSAL.tools.io.ProcessLauncher - launching C:\Program Files\VASSAL-3.6.5\jre\bin\java -Xms512M -Xmx512M -Duser.home=C:\Users\Ares -Duser.dir=C:\Program Files\VASSAL-3.6.5 -cp lib\Vengine.jar VASSAL.launch.Player --load – C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 09:49:36,913 [3252-main] INFO VASSAL.launch.StartUp - Starting
2022-03-30 09:49:36,929 [3252-main] INFO VASSAL.launch.StartUp - OS Windows 10 10.0 amd64
2022-03-30 09:49:36,929 [3252-main] INFO VASSAL.launch.StartUp - Java version 17.0.2
2022-03-30 09:49:36,929 [3252-main] INFO VASSAL.launch.StartUp - Java home C:\Program Files\VASSAL-3.6.5\jre
2022-03-30 09:49:36,929 [3252-main] INFO VASSAL.launch.StartUp - VASSAL version 3.6.5
2022-03-30 09:49:36,929 [3252-main] INFO VASSAL.launch.Launcher - Player
2022-03-30 09:49:40,937 [3252-AWT-EventQueue-0] INFO VASSAL.build.GameModule - Legion version 1.0
2022-03-30 09:50:39,347 [3252-AWT-EventQueue-0] WARN VASSAL.tools.ErrorDialog - Piece: A PS 1 Trait: Set Global Property - Test - Set Test Source: {LocationName.toString()} Error: Expression evaluation error. See the errorlog for more details.
Expression Audit:
Source type=Piece Trait
Source name=Piece: A PS 1
Source description=Trait: Set Global Property - Test - Set Test
Source Expression={LocationName.toString()}
Error=: Attempt to resolve method: toString() on undefined variable or class name: LocationName
2022-03-30 09:52:18,120 [3252-AWT-EventQueue-0] INFO VASSAL.build.GameModule - Exiting
2022-03-30 09:52:22,714 [6340-SwingWorker-pool-2-thread-3] INFO VASSAL.launch.AbstractLaunchAction - Loading module file C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 09:52:22,878 [6340-SwingWorker-pool-2-thread-3] INFO VASSAL.launch.TilingHandler - No images to tile.
2022-03-30 09:52:22,894 [6340-SwingWorker-pool-2-thread-3] INFO VASSAL.launch.AbstractLaunchAction - Loading module Legion
2022-03-30 09:52:22,899 [6340-SwingWorker-pool-2-thread-3] INFO VASSAL.tools.io.ProcessLauncher - launching C:\Program Files\VASSAL-3.6.5\jre\bin\java -Xms512M -Xmx512M -Duser.home=C:\Users\Ares -Duser.dir=C:\Program Files\VASSAL-3.6.5 -cp lib\Vengine.jar VASSAL.launch.Editor --edit – C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 09:52:24,480 [12984-main] INFO VASSAL.launch.StartUp - Starting
2022-03-30 09:52:24,496 [12984-main] INFO VASSAL.launch.StartUp - OS Windows 10 10.0 amd64
2022-03-30 09:52:24,496 [12984-main] INFO VASSAL.launch.StartUp - Java version 17.0.2
2022-03-30 09:52:24,496 [12984-main] INFO VASSAL.launch.StartUp - Java home C:\Program Files\VASSAL-3.6.5\jre
2022-03-30 09:52:24,496 [12984-main] INFO VASSAL.launch.StartUp - VASSAL version 3.6.5
2022-03-30 09:52:24,512 [12984-main] INFO VASSAL.launch.Launcher - Editor
2022-03-30 09:52:29,028 [12984-AWT-EventQueue-0] INFO VASSAL.build.GameModule - Legion version 1.0
2022-03-30 09:55:29,400 [12984-AWT-EventQueue-0] INFO VASSAL.tools.io.ProcessLauncher - launching C:\Program Files\VASSAL-3.6.5\jre\bin\java -classpath lib\Vengine.jar -Duser.dir=C:\Program Files\VASSAL-3.6.5 VASSAL.launch.ModuleManager --update-module C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 09:55:30,349 [12984-AWT-EventQueue-0] INFO VASSAL.build.GameModule - Exiting
2022-03-30 09:55:32,792 [6340-SwingWorker-pool-2-thread-4] INFO VASSAL.launch.AbstractLaunchAction - Loading module file C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 09:55:32,961 [6340-SwingWorker-pool-2-thread-4] INFO VASSAL.launch.TilingHandler - No images to tile.
2022-03-30 09:55:32,961 [6340-SwingWorker-pool-2-thread-4] INFO VASSAL.launch.AbstractLaunchAction - Loading module Legion
2022-03-30 09:55:32,976 [6340-SwingWorker-pool-2-thread-4] INFO VASSAL.tools.io.ProcessLauncher - launching C:\Program Files\VASSAL-3.6.5\jre\bin\java -Xms512M -Xmx512M -Duser.home=C:\Users\Ares -Duser.dir=C:\Program Files\VASSAL-3.6.5 -cp lib\Vengine.jar VASSAL.launch.Player --load – C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 09:55:34,348 [11188-main] INFO VASSAL.launch.StartUp - Starting
2022-03-30 09:55:34,364 [11188-main] INFO VASSAL.launch.StartUp - OS Windows 10 10.0 amd64
2022-03-30 09:55:34,364 [11188-main] INFO VASSAL.launch.StartUp - Java version 17.0.2
2022-03-30 09:55:34,364 [11188-main] INFO VASSAL.launch.StartUp - Java home C:\Program Files\VASSAL-3.6.5\jre
2022-03-30 09:55:34,364 [11188-main] INFO VASSAL.launch.StartUp - VASSAL version 3.6.5
2022-03-30 09:55:34,364 [11188-main] INFO VASSAL.launch.Launcher - Player
2022-03-30 09:55:38,318 [11188-AWT-EventQueue-0] INFO VASSAL.build.GameModule - Legion version 1.0
2022-03-30 09:55:52,051 [11188-AWT-EventQueue-0] WARN VASSAL.tools.ErrorDialog - Piece: A PS 1 Trait: Set Global Property - Test - Set Test Source: {LocationName.toString()} Error: Expression evaluation error. See the errorlog for more details.
Expression Audit:
Source type=Piece Trait
Source name=Piece: A PS 1
Source description=Trait: Set Global Property - Test - Set Test
Source Expression={LocationName.toString()}
Error=: Attempt to resolve method: toString() on undefined variable or class name: LocationName
2022-03-30 09:59:29,365 [11188-AWT-EventQueue-0] INFO VASSAL.build.GameModule - Exiting
2022-03-30 10:18:59,135 [6340-SwingWorker-pool-2-thread-5] INFO VASSAL.launch.AbstractLaunchAction - Loading module file C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 10:18:59,299 [6340-SwingWorker-pool-2-thread-5] INFO VASSAL.launch.TilingHandler - No images to tile.
2022-03-30 10:18:59,303 [6340-SwingWorker-pool-2-thread-5] INFO VASSAL.launch.AbstractLaunchAction - Loading module Legion
2022-03-30 10:18:59,307 [6340-SwingWorker-pool-2-thread-5] INFO VASSAL.tools.io.ProcessLauncher - launching C:\Program Files\VASSAL-3.6.5\jre\bin\java -Xms512M -Xmx512M -Duser.home=C:\Users\Ares -Duser.dir=C:\Program Files\VASSAL-3.6.5 -cp lib\Vengine.jar VASSAL.launch.Editor --edit – C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 10:19:00,768 [11404-main] INFO VASSAL.launch.StartUp - Starting
2022-03-30 10:19:00,784 [11404-main] INFO VASSAL.launch.StartUp - OS Windows 10 10.0 amd64
2022-03-30 10:19:00,784 [11404-main] INFO VASSAL.launch.StartUp - Java version 17.0.2
2022-03-30 10:19:00,784 [11404-main] INFO VASSAL.launch.StartUp - Java home C:\Program Files\VASSAL-3.6.5\jre
2022-03-30 10:19:00,784 [11404-main] INFO VASSAL.launch.StartUp - VASSAL version 3.6.5
2022-03-30 10:19:00,784 [11404-main] INFO VASSAL.launch.Launcher - Editor
2022-03-30 10:19:04,987 [11404-AWT-EventQueue-0] INFO VASSAL.build.GameModule - Legion version 1.0
2022-03-30 10:19:45,274 [11404-AWT-EventQueue-0] INFO VASSAL.tools.io.ProcessLauncher - launching C:\Program Files\VASSAL-3.6.5\jre\bin\java -classpath lib\Vengine.jar -Duser.dir=C:\Program Files\VASSAL-3.6.5 VASSAL.launch.ModuleManager --update-module C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 10:19:45,681 [11404-AWT-EventQueue-0] INFO VASSAL.build.GameModule - Exiting
2022-03-30 10:19:47,977 [6340-SwingWorker-pool-2-thread-6] INFO VASSAL.launch.AbstractLaunchAction - Loading module file C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 10:19:48,258 [6340-SwingWorker-pool-2-thread-6] INFO VASSAL.launch.TilingHandler - No images to tile.
2022-03-30 10:19:48,262 [6340-SwingWorker-pool-2-thread-6] INFO VASSAL.launch.AbstractLaunchAction - Loading module Legion
2022-03-30 10:19:48,270 [6340-SwingWorker-pool-2-thread-6] INFO VASSAL.tools.io.ProcessLauncher - launching C:\Program Files\VASSAL-3.6.5\jre\bin\java -Xms512M -Xmx512M -Duser.home=C:\Users\Ares -Duser.dir=C:\Program Files\VASSAL-3.6.5 -cp lib\Vengine.jar VASSAL.launch.Player --load – C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 10:19:51,604 [6172-main] INFO VASSAL.launch.StartUp - Starting
2022-03-30 10:19:51,632 [6172-main] INFO VASSAL.launch.StartUp - OS Windows 10 10.0 amd64
2022-03-30 10:19:51,632 [6172-main] INFO VASSAL.launch.StartUp - Java version 17.0.2
2022-03-30 10:19:51,632 [6172-main] INFO VASSAL.launch.StartUp - Java home C:\Program Files\VASSAL-3.6.5\jre
2022-03-30 10:19:51,636 [6172-main] INFO VASSAL.launch.StartUp - VASSAL version 3.6.5
2022-03-30 10:19:51,636 [6172-main] INFO VASSAL.launch.Launcher - Player
2022-03-30 10:19:56,096 [6172-AWT-EventQueue-0] INFO VASSAL.build.GameModule - Legion version 1.0
2022-03-30 10:20:07,860 [6172-AWT-EventQueue-0] WARN VASSAL.tools.ErrorDialog - Piece: A PS 1 Trait: Set Global Property - Test - Set Test Source: {LocationName.toString()} Error: Expression evaluation error. See the errorlog for more details.
Expression Audit:
Source type=Piece Trait
Source name=Piece: A PS 1
Source description=Trait: Set Global Property - Test - Set Test
Source Expression={LocationName.toString()}
Error=: Attempt to resolve method: toString() on undefined variable or class name: LocationName
2022-03-30 10:20:27,617 [6172-AWT-EventQueue-0] INFO VASSAL.build.GameModule - Exiting
2022-03-30 10:20:30,313 [6340-SwingWorker-pool-2-thread-7] INFO VASSAL.launch.AbstractLaunchAction - Loading module file C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 10:20:30,556 [6340-SwingWorker-pool-2-thread-7] INFO VASSAL.launch.TilingHandler - No images to tile.
2022-03-30 10:20:30,563 [6340-SwingWorker-pool-2-thread-7] INFO VASSAL.launch.AbstractLaunchAction - Loading module Legion
2022-03-30 10:20:30,568 [6340-SwingWorker-pool-2-thread-7] INFO VASSAL.tools.io.ProcessLauncher - launching C:\Program Files\VASSAL-3.6.5\jre\bin\java -Xms512M -Xmx512M -Duser.home=C:\Users\Ares -Duser.dir=C:\Program Files\VASSAL-3.6.5 -cp lib\Vengine.jar VASSAL.launch.Player --load – C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 10:20:32,883 [13200-main] INFO VASSAL.launch.StartUp - Starting
2022-03-30 10:20:32,911 [13200-main] INFO VASSAL.launch.StartUp - OS Windows 10 10.0 amd64
2022-03-30 10:20:32,911 [13200-main] INFO VASSAL.launch.StartUp - Java version 17.0.2
2022-03-30 10:20:32,911 [13200-main] INFO VASSAL.launch.StartUp - Java home C:\Program Files\VASSAL-3.6.5\jre
2022-03-30 10:20:32,911 [13200-main] INFO VASSAL.launch.StartUp - VASSAL version 3.6.5
2022-03-30 10:20:32,911 [13200-main] INFO VASSAL.launch.Launcher - Player
2022-03-30 10:20:33,999 [6340-SwingWorker-pool-2-thread-8] INFO VASSAL.launch.AbstractLaunchAction - Loading module file C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 10:20:34,244 [6340-SwingWorker-pool-2-thread-8] INFO VASSAL.launch.TilingHandler - No images to tile.
2022-03-30 10:20:34,248 [6340-SwingWorker-pool-2-thread-8] INFO VASSAL.launch.AbstractLaunchAction - Loading module Legion
2022-03-30 10:20:34,254 [6340-SwingWorker-pool-2-thread-8] INFO VASSAL.tools.io.ProcessLauncher - launching C:\Program Files\VASSAL-3.6.5\jre\bin\java -Xms512M -Xmx512M -Duser.home=C:\Users\Ares -Duser.dir=C:\Program Files\VASSAL-3.6.5 -cp lib\Vengine.jar VASSAL.launch.Player --load – C:\Moduli Vassal in elaborazione\Legion\Legion.vmod
2022-03-30 10:20:36,556 [3724-main] INFO VASSAL.launch.StartUp - Starting
2022-03-30 10:20:36,579 [3724-main] INFO VASSAL.launch.StartUp - OS Windows 10 10.0 amd64
2022-03-30 10:20:36,579 [3724-main] INFO VASSAL.launch.StartUp - Java version 17.0.2
2022-03-30 10:20:36,579 [3724-main] INFO VASSAL.launch.StartUp - Java home C:\Program Files\VASSAL-3.6.5\jre
2022-03-30 10:20:36,579 [3724-main] INFO VASSAL.launch.StartUp - VASSAL version 3.6.5
2022-03-30 10:20:36,583 [3724-main] INFO VASSAL.launch.Launcher - Player
2022-03-30 10:20:38,483 [13200-AWT-EventQueue-0] INFO VASSAL.build.GameModule - Legion version 1.0
2022-03-30 10:20:42,972 [3724-AWT-EventQueue-0] INFO VASSAL.build.GameModule - Legion version 1.0
2022-03-30 10:21:20,836 [13200-AWT-EventQueue-0] INFO VASSAL.build.GameModule - Exiting
2022-03-30 10:21:24,856 [3724-AWT-EventQueue-0] INFO VASSAL.build.GameModule - Exiting

  1. To Brent_Easton : damn it! If there is a bug be sure that it will hit me!

Thank you a lot for your support.

:slightly_smiling_face:

Well, so hopefully @Brent_Easton is on the trail, as that’s exactly what I would hope .toString() would handle. As for “location” - I don’t use that but from your experience it looks like a synonym for LocationName.

Ok, I believe I have made progress in both the report .toString() problem and with the on-going disappearing zeros issues.

Please try the BseanshellTostringIssue (sic) build at Builds of vassalengine/vassal

The toString() function had been left out of the list of String functions that are specially handled when evaluating Beanshell functions directly on property names. This cause the Bad Data Error you where seeing.

Then I discovered that SetGlobalProperty was evaluating the Beanshell expression, then re-evaluating it and it was the second evaluation that caused the leading zeros to be stripped as the BeanShell interpreter converted 0707 to 707.

This new version skips the second evaluation UNLESS there happens to be any un-evaluated $$ variables left in the expression which require a second level of evaluation.

You should find that setting the global property to either {LocationName.toString()} or {GetString(“LocationName”)} should retain the leading zeros.

Regards,
Brent.

2 Likes

Hello Brent,

thanks a lot for trying to solve this damned problem that has haunted me for years. I made some other tests using BseanshellTostringIssue build , but, unfortunately, the leading zero is still vanishing.

I’m simulating the return of an aircraft to Air Base after an air attack. The location of the Aire Base is entered with a prompt
and loaded on a Dynamic Property. The Dynamic Property is not defined as numeric.


Then the content of this Dynamic Property is loaded onto another Dynamic Property using the GetString function.

It looks like (see the report) that the leading 0 vanished when the first Dynamic Property was loaded from prompt.
Even worse, I loaded the content of LocationName (the actual position of the Air Unit) onto the Dynamic Property CurrentHex using LocationName.toString(), but, as you can see, the leading zero vanished again.


Sorry for reporting this, but this was happened. Maybe I’m using the wrong syntax, I don’t know.

I’m sure you will eliminate this bug soon!

Be well.

Panther_2010

To resolve a problem you can use parenthesis around the variable, i.e. (LocationName).toString(), but note that leading zero(s) will be removed from the result.

What I want is that that damned leading zero will NOT be removed.

:face_with_symbols_over_mouth:

Thanks, i will investigate further. The double evaluation problem I identified in Set Global property probably also exists in the Dynamic Property code.

leading zero removed! System treating the ‘value’ as a value (number). Can the system be forced to treat the ‘value’ as a string “0123” stays as 0123.
Just a thought.

I’m sure Brent will fix it. :upside_down_face:

It is not nearly that easy, it depends on the context, which is not easy to determine

0123 + 1 = 124

“0123” + 1 = “01231”

“0123” * 2 = Illegal

I can change the interpreter so that 0703 always gets converted to a String and is treated as a String so that 0703 + 1 = 07031 and 07030 * 1 generates an error.

My concern is that are there any modules that depend on 0703 + 1 = 704?

Is it possible to treat properties as Strings unless a mathematical operation is required (i.e., if a calculation includes +-*/ etc., only then do you convert the property to an integer)? And then allow String.concat() for those occasions when someone really wants "0123" + "1" = "01231" instead of "0123" + "1" = 124?

And, do this in a backwards-compatible way? :smiley:

1 Like

Potentially, at the expense of re-checking every single operand whether it is an Integer or not every time each and every individual mathematical operation is evaluated. This should be backward compatible, but with a performance hit

Left-field on the problem; what is the RegEx to left-pad a fixed length value ?