Not sure if many people are aware, but Beanshell fully supports Java math and string functions:
vassalengine.org/wiki/How_to … _in_VASSAL
vassalengine.org/wiki/How_to … _in_VASSAL
I’ve already updated the wiki articles above with some hard-earned discoveries made by experimenting with those functions. One area I was encountering nothing but problems with was the usage of GetProperty in conjunction with those functions. So I thought I’d solicit opinions of those who are more familiar with the Vassal engine source code. I’ve had no problems working with Dynamic or Global Properties. Those are clearly defined as integers or strings, so virtually any Java manipulation worked. However, it seems like anything generated by GetProperty is neither a string nor an integer (maybe some other non-primitive type). For instance:
Integer.toString(Prague_Units).replace(“0”,"").length()
Prague_Units is a numeric Global Property so Vassal reports it as an integer to Java. The above function converts that integer to a string, then replaces any “0” characters with a blank, and finally reports the length of that string. It works great. However, the same exact function fails when evaluated using GetProperty in place of a numeric Global Property:
Integer.toString(GetProperty(LocationName+"_Units")).replace(“0”,"").length()
LocationName=“Prague”
I got Java errors telling me it was expecting an integer, but that GetProperty(LocationName+"_Units") wasn’t an integer. OK fine, it’s a string. So then I changed the expression to:
GetProperty(LocationName+"_Units").replace(“0”,"").length()
Then, I got Java errors telling me it was expecting a string, but that GetProperty(LocationName+"_Units") wasn’t a string. So I thought “hmm, maybe it’s undefined” and forcing it to be a string before passing it off to Java would work:
(GetProperty(LocationName+"_Units")+"").replace(“0”,"").length()
Nope. Lastly, I tried:
Integer.toString(GetProperty(LocationName+"_Units"+0)).replace(“0”,"").length()
Low and behold that worked!
So I’ve been able to unlock virtually every Java function through trial and error like this, but just curious if anybody knows what non-primitive type Vassal is handing off to Java with GetProperty…