Doing Math

Okay, I’ve started work on an all-new version of the Federation & Empire module, and I’d like to incorporate a couple new features that I need help on:

Is there any way to have decimals in properties in Vassal 3.2? I know you couldn’t in 3.1.x, and I was hoping that support for that was one of the new things in 3.2. My testing says it still can’t be done, but if I missed something, I want to toss it out there.

The current module attaches a large number of numerical properties to each unit, so that you can easily see the combined total in the stack viewer.

The problem is that it is common to use ‘fleet markers’ to represent large collections of units, to keep stacking down. In the module, these are separate counters that are associated with a extra map window where the unit counters are kept. I would like the marker to report statistics in line with all the ships in the appropriate map.

I can think of two ways of doing this, but both are beyond my understanding for being able to implement:

  1. The counter has a (for example) Attack Factor property that is equal to the sum of all the Attack Factor properties present in a particular map(/zone).

  2. Every time a counter is placed or removed from the map window, it fires a hidden key command that raises/lowers the value of the appropriate properties on the associate fleet marker.

The first option is much more robust, and is preferable, but I’m not sure it’s currently possible. The second option, I’m pretty sure is possible, but I haven’t done much with with the Global Key Commands.

Okay, just made another stab at the first part (‘simple’). Going off an idea on another board, I looked at seeing if storing all the SEs (the trait in question) doubled, and then dividing by two for the stack viewer would work.

Well, I can’t find a way to do it. Functions like ‘sum’ exist, but if there’s a way to tell it to divide in the summary text box, the syntax is not obvious.

Which is about what I expected. But it really does bring up the fact that I’m flying blind. I don’t even know what the available functions are. I’m borrowing someone else’s work for the sum function in the first place.

Okay, I looked at using a Calculated Property this time. Set a Dynamic Property (SEB) to double what SE should be, then set a Calculated Property (SE) to SEB/2.

That actually partially worked. A ‘4’ SEB reported as ‘2’ SE in the stack viewer, naturally. However, a ‘1’ SEB reported as ‘0’ instead of ‘0.5’ in the stack viewer. Which is an improvement, as just setting a Dynamic Property to 0.5 just gets a “?” in the stack viewer. Stacking two counters at 0.5 SE each still reports 0 however, so it’s getting truncated on the Calculated Property side, which is probably why the stack viewer is fine.

Anyway, I started looking at Calculated Properties in the first place to work out how to make the Fleet Markers work. …And I’m lost. Again. It really looks like what I want is in there, but I just don’t get how to get at it.

So here’s what I want: Assume Game Pieces have a numeric Property ‘SE’. Assume some of them exist in a Map Window called ‘Home Fleet’ (with a Zone of a similar/same name). I want a Calculated Property that is equal to the sum of SE for all Game Pieces currently in that Zone (or Map, if that’s easier, though I suspect Zone is what is wanted).

Ticking the checkbox for “Is numeric” on Dynamic or Global Properties restricts them to integer values only:

…so maybe that’s why the Calculated Property is getting screwed up. A Dynamic Property with a value of 0.5 might be getting interpreted as a string. I admit I’ve only used Calculated Properties sparingly, and only with integer values. The feature isn’t documented so I’m not sure what its limits are.


Okay, I so I tried doing a Dynamic Property that wasn’t numeric. Found out that it’ll still work as a number, and the stack viewer can sum them together. I also figured out how to swap values back and forth through an IF instead of cycling through math (which wasn’t an option here). That could be handy with some ideas I have later down the road. Anyway, values of 0.5 show up as zero, and add up to zero, so still no-go in getting around this problem. But, again, it doesn’t generate the ‘?’ that feeding the stack viewer a non-whole number does.

So, back to my second problem.