Need pointer to JAVA example or tutorial

Hi Matt,

Oracle - the owner of the Java platform - has a number of Java tutorials covering a lot of different topics.

Of course, these tutorials do not address the VASSAL Application Programming Interface (API) - you can find the documentation of that here. This is the API documentation and does not contain a tutorial.

That said, I’m not sure you are after is a tutorial on Java, nor the VASSAL API. Let me give a bit of context.

When VASSAL encounters an element in the module XML file, say

<Foo ...>
</Foo>

it will check to see if the Java class Foo is known or can be loaded from the module (or anywhere in the current class path, but that’s a detail). If so, it creates an object of that class (it instantiates an object - or instance - of the that class) passing appropriate parameters for the classes constructor. The Foo class could look like

class Foo 
{
    public Foo() {} 
    int _bar
}

in Java source code.

That object then exists as long as the module is loaded in the current Java virtual machine.

One can use this to make custom elements in the module, for example ObliqueHexGridNumbering creates a hex-number scheme which is oblique, unlike the VASSAL-provided more rectangular hex-number scheme.

What I think you are after, is really a tutorial on BeanShell. A general quick-start on BeanShell exists. The VASSAL BeanShell API is documented through the VASSAL Reference Manual.

For your specific question

I do not believe that it is easily possible to define a new BeanShell function from within a VASSAL module (I would love to know how myself). One could possible create a new element class, say BeanShellFunctionLibrary, which, on instantiation - i.e., when the module is loaded - get a hook to the BeanShell interpreter and add new functions to it.

So what I think you would like to do, is to create a prototype with appropriate DynamicProperty, Trigger, etc. traits. You can use a GlobalProperty to store the possible hits, and then by selecting (possibly at random), and an treat that as an array looking up the selected index. A Report trait can write your message to the chat. The prototype can then be added to any ship.

With the above suggested prototype you will get this more or less for free. Heck, you can even make the chat message contain the name of the ship.

Hope that helps.

Yours,
Christian