Can't get custom trait to stick

Understand I have to modify the buildfile as well as load the class into the zipfile. Have done the latter, cannot figure out the former.

My class is in VASL/counters/TextInfo.class

I get the impression from various posts that I can replace or modify the line

<VASSAL.build.module.BasicCommandEncoder/>

if so, what should it be?

Thanks for any help

Thus spake gravey101:

Understand I have to modify the buildfile as well as load the class into
the zipfile. Have done the latter, cannot figure out the former.

My class is in VASL/counters/TextInfo.class

I get the impression from various posts that I can replace or modify the
line

<VASSAL.build.module.BasicCommandEncoder/>

if so, what should it be?

If you’re intending to relplace VASSAL.build.module.BasicCommandEncoder
with VASL.counters.TextInfo, then the line should be

<VASL.counters.TextInfo/>

but I doubt that’s what you actually want. If all you’re trying to do
is add a custom class, you should do that from the Editor. (Bring up
a context menu, choose “Add Imported Class”.)


J.

yeps that is all i am trying to do, but when i do that, and assign the custom trait to a piece, when i reload the module the custom trait is replaced by ‘marker’. Looking around a bit i see that others have had the same problem and had to modify the buildfile. Is that not the case?

You need to define a custom command encoder to be able to translate your trait to and from the string that is stored in your saved module. Tim has a very good, basic example in the forums here:
https://forum.vassalengine.org/t/programming-tutorial-mycounterfactory-class/4627/1
What’s happening right now is that the basic command encoder is trying to parse your encoded custom trait, not finding a matching basic trait, then giving up and making it a Marker. Check around line 303 here:
vassalengine.svn.sourceforge.net … iew=markup
I bet you’re also getting an ‘Unknown type’ error in your chat window.

-Seth

Oh, and yes you will need to modify the buildfile. In the line that you identified, replace ‘VASSAL…BasicCommandEncoder’ with the fully qualified class name of your own command encoder (which is what Tim’s example is).

Thanks Seth…

yeh I saw that post and have been trying to get that setup.

So, Java not being my thing, I have blundered about a bit with Eclipse and tried to create a custom encoder class but so far it has been a bit of a time-intensive failure. Do I need the entire VASSAL development environment to be able to do this, or should I be able to create the class standalone ?

The best thing if I recall correctly is to include the .jar files found in the lib directory of your Vassal installation - this will help Eclipse build your import statements appropriately. Here is my complete DominionCommandEncoder.java, from when I was playing around with my own custom traits:

[code]package Dominion;

import VASSAL.build.module.BasicCommandEncoder;
import VASSAL.counters.Decorator;
import VASSAL.counters.GamePiece;

public class DominionCommandEncoder extends BasicCommandEncoder {
public Decorator createDecorator(String type, GamePiece inner) {
if (type.startsWith(PropertyTable.ID)) {
return new PropertyTable(type, inner);
}
if (type.startsWith(ConditionalReport.ID)){
return new ConditionalReport(type, inner);
}
return super.createDecorator(type, inner);
}
}[/code]

In this case, PropertyTable and ConditionalReport are classes in the ‘Dominion’ package and do not require import statements.
The .class files for all three classes (including this command encoder) are in a ‘Dominion’ subdirectory in my module. My buildfile is modified to reference <Dominion.DominionCommandEncoder/> instead of the BasicCommandEncoder.

Cheers,
Seth