If problems

I am new to working on Vassal modules and I have been having trouble using “If” function.
I get Unhandled Exceptions, for example, when trying the following in the Text box of the Text Label trait. I am not sure that I have the syntax correct and maybe vassal doesn’t allow use of the If statement where I would like to use it.
Can anyone shed any light on my issue or point me in the direction of helpful examples or documentation ?

Example of a conditional that triggers vassal to crash:-

{If(Nation==-1,GetProperty(“Set Lead Army_Name”),"")}

The GetProperty clause works on its own, but adding the wrap-around If statement gives an exception. Similarly, using the ? operator like so give an error too.

{If(Nation==-1 ? GetProperty(“Set Lead Army_Name”) : “”)}

Initial lines of error log follow.

Mark.


2020-05-25 18:27:06,671 [0-main] INFO VASSAL.launch.StartUp - Starting
2020-05-25 18:27:06,676 [0-main] INFO VASSAL.launch.StartUp - OS Mac OS X 10.15.4
2020-05-25 18:27:06,676 [0-main] INFO VASSAL.launch.StartUp - Java version 1.8.0_251
2020-05-25 18:27:06,677 [0-main] INFO VASSAL.launch.StartUp - VASSAL version 3.2.17
2020-05-25 18:27:07,537 [0-AWT-EventQueue-0] INFO VASSAL.launch.ModuleManager - Manager
2020-05-25 18:28:26,043 [0-SwingWorker-pool-1339434293-thread-1] INFO VASSAL.launch.AbstractLaunchAction - Loading module file /Users/Mark/Documents/Vassal Modules/CCNapoleonics3_43G3.vmod
2020-05-25 18:28:26,496 [0-SwingWorker-pool-1339434293-thread-1] INFO VASSAL.launch.TilingHandler - No images to tile.
2020-05-25 18:28:26,497 [0-SwingWorker-pool-1339434293-thread-1] INFO VASSAL.launch.AbstractLaunchAction - Loading module Commands & Colors: Napoleonics
2020-05-25 18:28:26,521 [0-SwingWorker-pool-1339434293-thread-1] INFO VASSAL.tools.io.ProcessLauncher - launching /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -Xms256M -Xmx512M -DVASSAL.id=1 -DVASSAL.port=60235 -Duser.home=/Users/Mark -Duser.dir=/Applications/VASSAL 3.2.17.app -cp Contents/Resources/Java/Vengine.jar -Xdock:name=Commands & Colors: Napoleonics -Xdock:icon=/Applications/VASSAL 3.2.17.app/Contents/Resources/VASSAL.icns -Dapple.awt.graphics.UseQuartz=false VASSAL.launch.Editor --edit – /Users/Mark/Documents/Vassal Modules/CCNapoleonics3_43G3.vmod
2

I would not expect BeanShell to evaluate properly on the fly in the Text box of a Text Label trait–if it’s doing so in some cases, that might be serendipity more than design.

Try putting your IF statement in a Calculated Property trait on this piece, then use the Text Label to display that Calculated Property.

Thank you, Joel. That’s where I was going wrong.

{If(Nation==-1 ? GetProperty("Set Lead Army_Name") : "")}

The ? operator is not supported by Beanshell, you need to use the If function as per the manual:

{If(Nation==-1, GetProperty("Set Lead Army_Name"), "")}