Dynamically create PieceSlot for PieceWindow ListWidget

Dear all,

I have the following question:
So I am trying to create in code the some PieceSlot on some objects.
They are added, but I don’t see the real name and I am not sure on how to include the image of the Piece slot. This is my code so far:
PieceSlot newPieceSlot = new PieceSlot();
_logger.info(“unit name” + testUnit.get_unitFullName());

            newPieceSlot.setAttribute("name", testUnit.get_unitFullName());
            newPieceSlot.setAttribute("entryName", testUnit.get_unitFullName());

            //generate images

            newPieceSlot.setAttribute("pieceDefinition", "test.PNG");
            _logger.info("new PieceSlot: " + newPieceSlot.getName() + " " + newPieceSlot.toString());

Anyone has any experience with this?

Before I give any advice, could you please describe what you are trying to achieve?

Dynamically set up module content with external data, which also means the pieceslots.

I’m not sure why you expect this to do anything at all when the definition of PieceSlot.setAttribute() is

  public void setAttribute(String name, Object value) {

Calling random methods and passing random data as arguments is not going to get you very far. What you are trying to do is not easy and requires an in-depth knowledge of Vassal internals. Based on other programmers coming new to Vassal, the skills you need can be built up over a couple of months of intensive study.

You will need to investigate the PieceDefiner and how it builds GamePieces and generates pieceDefinitions. Try running Vassal under a debugger and look into the data structures it is building and passing around.

If you have a pre-existing GamePiece, you can call PieceSlot.setPiece() to set that piece into the PieceSlot.

That GamePiece will need to be built up from a BascPiece and any Decorators you require to implement that piece.


Will do more investigation and debugging for further understanding. Thanks for the small hint!

Looking at the debugging now, but how would you ideally be able to debug a module with maven?
Would you create a main class around the module? Or create a method in VASSAL engine, that will directly call that module?

got it working. Strange…I changed args to vmargs, that failed, switched it back to args, then it worked.