Marker values in Beanshell and debug popup

I have a marker property called Initiative.

I can refer to it in a Beanshell expression in a report action as
$Initiative$

{Initiative}

Initiative.toString()

GetProperty(“Initiative”)

it works fine.

When I add it to a larger debug popup, it errors with a Bad Data in Module Piece error.
I find the properties pop handy for debugging.
It works fine without the initiative lines.

{
out = “”;

out = out + "PieceName = " + GetProperty(“PieceName”) + “\n”;
out = out + "BasicName = " + GetProperty(“BasicName”) + “\n”;

out = out + "LocationName = " + GetProperty(“LocationName”) + “\n”;
out = out + "OldLocationName = " + GetProperty(“OldLocationName”) + “\n”;

out = out + "CurrentX = " + GetProperty(“CurrentX”) + “\n”;
out = out + "CurrentY = " + GetProperty(“CurrentY”) + “\n”;
out = out + "OldX = " + GetProperty(“OldX”) + “\n”;
out = out + "OldY = " + GetProperty(“OldY”) + “\n”;

out = out + "MapName = " + GetProperty(“MapName”) + “\n”;
out = out + "CurrentMap = " + GetProperty(“CurrentMap”) + “\n”;
out = out + "CurrentBoard = " + GetProperty(“CurrentBoard”) + “\n”;

out = out + "DeckName = " + GetProperty(“DeckName”) + “\n”;
out = out + "Layer = " + GetProperty(“Layer”) + “\n”;

out = out + "Initiative = " + Initiative.toString() + “\n”;
out = out + "Initiative = " + GetProperty(“Initiative”) + “\n”;

Alert(out);
“”
}

cheers

Gus

Did you check the errorLog. Often it will give a bit more information about that is possibly wrong.

You should be able to simply do

out = out + "PieceName = " + PieceName +"\n";

or even

out += "PieceName = " + PieceName + "\n"

Which specific line makes the code fail?

You could try

out += "Initiative = " + GetString("Initiative") + "\n";

If Initiative has type of something that does not have the toString method, then the above could fail. The BeanShell function GetString will check for such circumstances and take appropriate actions.

Another possible explanation is that the properties are not defined in the context in which your code is executed. In all other cases than Initiative you retrieve the property values with GetProperty which is fault tolerant if the property isn’t defined. You could try - though I’m not sure it is supported by BeanShell - the code

try { 
  out += "Initiative = " + Initiative.toString() + "\n";
} catch (Exception e) {
  out += "Initiative = unknown\n"
}

Yours,
Christian

Hi Christian,

Thanks for your explanation.

This works (woohoo :slightly_smiling_face: )
out += "Initiative = " + GetString(“Initiative”) + “\n”;

I am not in VASSAL often and I find that the debug window really helps.

I’ll check out the error log as well.

Thanks

Gus

I often define a boolean Debug Preference and then have reportFormat or report like

{Debug ? ("~"+PieceName+" has ....") : ""}

and attach a bunch of Report Action traits to various actions. Then, if I set the preference to true, I can get a trace of the actions taken in the chat log. If I turn off the debugging, I get nothing (the tertiary expression <condition> ? <then> : <else>). Very useful when hunting down things that doesn’t work as expected.

I don’t often use the Alert feature, because it requires user interaction :slight_smile:

See most of the modules I’ve made for examples.

Yours,
Christian