How to add a script to a module?

Hi moderators and folks

I have created an utility to easily and quickly calculate Ground Combat Modifiers when playing “A Time for Trumpets”.
The usefulness of this little script is to calculate the possible Combat Column Shifts and Combat Die Roll Modifiers by simply selecting Checkboxes. So it is very easy to use.
The results are written in a simple text file, on two lines ("Shift = " and “DRM =”).
You will find here a tuto of this little software.

I wrote it in python3.

I would like to introduce this utility in the module of aTfT.
It would be accessible for example by a button in the general menu.
The results would then be displayed in the dialog box, on two line, much like in the great module (GTS Operation Mercury: The Invasion of Crete from MMP) that Brent has developed.

I’m not sure how to do this and I would need your advice.

  1. Does the script have to necessarily be written in java (or javascript)?

  2. If it is not necessary to be in java, can we consider a java script that make open the (or an equivalent windows executable file) and another one that retrieves the results in the text file where they are located (once calculated) and display them in the dialog box? I know it’s a bit twisted. The first Java Script opens the python script, this one writes the results in a text file by the action of a button which itself relaunches a second java script which will retrieve the data in the text file.

  3. If it is necessary to be in java, which in itself would be more rigorous and easier, I can try to rewrite this script in java (although I am not a java expert). But the question remains the same, what code to return the results in the dialog box?

  4. To call the utility by a button of the general menu I suppose we use the classic method of a Hotkey linked to a GKC calling a piece where a trait would have been created by an “import” of a “fully-qualified name of Java class”. Is it right?

Could you advise me?

Or are there any tutorials on this site that could enlighten me and help me to realize this project?

Thank you very much for your help

Jean Phi

Yes, all V3 scripting must be in Java.

Ok thank you Joel. I gonna try my best to recode to java with the help of my son who is a java specialist since it is his job.
That said, is there a tutorial on the Vassal site that explains how to code a result feedback in the dialog box?


Jean Phi

If you don’t want to recode This page gives a number of methods for invoking Python from Java.

Unfortunately, the methods based on jython are not available to you because jython only handles Python 2.7


Thank you very much

Indeed I am using python 3. I think that the simplest and most rigorous would be to rewrite in Java. That said the exe I made from the .py works very well and users of the Vassal module can use the exe in parallel with the module as well. Wanting to integrate it to the module is a plus but I think it’s a lot of work for not much. That the players have access to the script from the module or that they open it in parallel finally amounts to the same thing.
But thanks for your answer.
That said, I’m looking and studing how to create Custom Classes. I finally found some tutorials on the site :slight_smile:

Jean Phi

That absolutely won’t work for anyone using Linux or MacOS.

If you’re going to have custom code that works for anyone using the module, you need to consider users of other operating systems—which means writing your custom code in Java.

Yes indeed Joel

Of course the exe works only with windows. I put it in free service for those who want it on the CSW forum for aTfT, and some have already claimed me for Mac. Linux and Mac users unfortunately can’t use it.
So that was kind of the reason why I thought to integrate it into the module. Writing it in Java and integrating the script would indeed solve this problem, any user would have access via the module whatever their operating system.
As I said above I am not a Java specialist. Hence my first post, I wanted to know if there was a way around it. Obviously not. I have to resign myself to put my nose in Java. It won’t be done in two days :slight_smile:

Anyway, thanks for your help

Hi all,

One way to run a Python script from VASSAL would be to open a pipe, to the Python executable, write the Python script to the pipe (standard input for Python), and then read the response from the pipe (standard output of Python). To make it work on all platforms one may need to do a little discovery so as to find the right Python executable. However, this method is not very efficient nor very robust, and opens a potential security hole (albeit manageable if you’re careful). The best alternative is to recode in Java, which shouldn’t be too difficult.



Thank you Christian

The utility I made is nothing but a GUI, with scrollbars, an image, checkboxes and two buttons. As you said it shouldn’t be too difficult. With patience I think I should be able to recode this in Java, and it can be interesting for me, it would be a first approach toward this language that I don’t practice.

Jean Phi