Create account / Log in

Any String Functions in VASSAL?

Issues with the Vassal engine.

Moderators: uckelman, Tim M

Any String Functions in VASSAL?

Postby ianclarence » January 14th, 2018, 1:49 am


Are there any string functions in VASSAL? I can't see any in the Designer Guide.

Specifically I need to (a) find the length of a string and (b) extract the Nth character.


Posts: 11
Joined: April 28th, 2015, 10:12 pm

Re: Any String Functions in VASSAL?

Postby Cattlesquat » January 31st, 2020, 6:36 pm

Yes! In a beanshell "expression", java string functions are available. So you would be looking for the str.length() and str.charAt(n) functions.

But I have found that I can't just pass in the property name directly, I have to use GetProperty.

So for example instead of e.g. LocationName.length() I find I need to use GetProperty("LocationName").length()

Examples of string voodoo I have successfully accomplished in Vassal:

#1 Here is an expression I have used to check if the current location is listed in the table of victory objectives spaces (and give me 1 or 0 as the result). In this case I have two different AP_Objectives tables (AP_Objectives_0 and AP_Objectives_1) and I pick which one based on the global Variant property:

#2 Here I take a LocationName in the format "Turn 17", delete everything that isn't a 0-9 digit, and parse back into an integer value (which in the example of "Turn 17" would give me 17)

I would have expected I could just say LocationName.length() or whatever, but for whatever reason I only got it to work once I started using GetProperty.

I hope this is helpful! It was hard-won knowledge since I couldn't find functioning examples anywhere!

User avatar
Posts: 804
Joined: December 2nd, 2019, 4:57 pm
Location: Baltimore, Maryland, USA

Re: Any String Functions in VASSAL?

Postby ianclarence » February 1st, 2020, 6:17 pm

Thanks Brian! This is great stuff.

I know this is going to be very useful except... right now I can't quite remember what I needed it for.

Never mind this kind of not-in-the-manual knowledge is very much appreciated.

Posts: 11
Joined: April 28th, 2015, 10:12 pm

Return to Technical Support & Bugs

Who is online

Users browsing this forum: No registered users and 1 guest