You can take a look at the BeanShell Quick Start. However, Vassal doesn’t really exploit the full capability of BeanShell, and many of the things covered there are not really relevant. In fact, the most relevant part for Vassal is to understand the difference between variables and values, as outlined a previous post in this thread.
Another feature, is the ternary condition operator:
boolean-expression ? then-expression : else-expression
This expression evaluates to then-expression if boolean-expression evaluates to true (or a non-zero value, or a non-empty string - in case of Vassal), otherwise to the else-expression. For example,
Type == "FSA" ? 1 : 0
evaluates to 1 if the variable Type has the string value "FSA", otherwise it evaluates to 0.
Finally, there’s understanding call-sequences. You can call functions, such as CountStack but you must take care to pass the function arguments that the function expects. For example, CountStack expects either
- The name of a property - e.g.,
"Type",
- An expression - e.g.,
Type=="FSA", or
- A property and an expression.
Sometimes the functions are “embedded” in a class - more correctly named methods or member functions like the String functions. For example, to test if a variable A, which holds a string value, contains the (sub-)string “B”, one should do
A.contains("B")
One can old-style property value references - $property$ - and BeanShell code, it is important to note that the values are substituted in before the BeanShell expression is evaluated. Suppose a piece has the property $A$, which contains the value B (no type - old-style properties have no type), and you want to compare the value to some other value - say "C", then one must do
{"$A$" == "C"}
because B (without quotes) is substituted in for $A$ to yield the BeanShell expression
"B" == "C"
If you did not quote the $A$ substitution, you would get the expression
B == "C"
which will compare the value of the variable (or property) A to the value (or constant) "C", which is not the same thing. Incidentally, this “substitution” mechanism is what one uses when one piece asks another piece to compare that second pieces property to the value of the first piece. I.e., piece a has the property A with the value aaa, and piece a then asks piece b to compare its property B’s value to the value of A. It would do so by doing
{ B == "$A$" }
which will result in the expression
B == "aaa"
being evaluated in the context of piece b.
That’s more or less what there is to know about BeanShell code in Vassal. You can also refer to the reference manual - for example Properties and Expressions for specific features. Most of these contains a fair bit of examples to help you understand how they work.
Yours,
Christian