There is a long thread in this forum about an undo bug. I was having my own flavor of an undo problem, so I added to that thread and created some bare-bones vmods to isolate the problem. What I discovered though was unexpected. It wasn’t an undo problem (although undo deserves jail time); it was a stacking problem. Or at least my evidence implicates it.
In my working module (the game Barrage), if I pressed a button, all units in zones would go to regions based on the zones where they started. Effectively, they hopped from zone to zone. I named the zones as numbers (‘1’ to ‘6’), so pieces in ‘1’ went to ‘2’, ‘6’ went back to ‘1’, and so on. This worked 95% of the time, but on rare occasions units would skip a zone and hop from ‘2’ to ‘4’. A race condition? Don’t know. I implemented this with a button and “send-to-region” commands.
(An aside for Mr Flintb et al who might not understand. A zone is a named map area, triangle, square, etc that a module-maker can create. Vassal knows when pieces are in or out of zones, and it can send pieces to zones. A region is a named point on the map. It has an (x,y) format and calling it a region is misleading. In my working module, my zones were pie slices. In my test module, they were squares, 200 pixels on a side.)
It worked well enough, but I discovered if I did an ‘undo’, it was a 100% certainty that those hopping pieces would screw up, not during the undo, but later, after it was done. It was as if the undo poisoned the module. Pieces started skipping zones and joining brother pieces in farther zones, from ‘2’ to ‘4’ for example. When I asked the piece where it came from, it lied and said ‘3’, not ‘2’. More on this in a moment because it turns out, I don’t think it was lying.
So I made a small test module where my zones were squares, and to simplify I decided I would “send-to” pieces from zone to zone instead of to region. To my chagrin, I discovered the pieces began skipping zones without me ever doing an undo. Oh, they wouldn’t start immediately, they’d wait a move, but sure enough at the same exact time some of them would jump ahead and join its brothers. (If anyone wants to see the tiny test module, let me know.)
When I disabled map stacking, all the pieces behaved correctly in my test and working modules. The rat was in the “stacking” woodpile. “Undo” was guilty of assisting a felon, but it was not the felon.
One possibility was Vassal was screwing up the radius of effect. When you send-to or drag-and-drop a piece too close to another, vassal will suck them together in a single stack. I don’t know what that radius is, but I’m pretty sure it’s not 200 pixels. Perhaps it wasn’t calculating the distance between pieces properly?
A better possibility and the culprit I think: When I pushed the button and the pieces in zone ‘2’ went to zone ‘3’, they temporarily stacked with the pieces starting in zone ‘3’, who had tickets to go to 4. When the pieces starting in 3 moved to 4, those who just got to 3 decided to tag along to 4. In short, I think vassal moved the entire stack in 3 to 4 when it should have sorted through the ‘3’ stack and only moved the selected pieces, not everyone.
I have evidence that supports this. For example, if pieces are separated by zones so they never temporarily stack, nothing goes wrong. If I have only one piece in all zones, nothing goes wrong. I could refine the test module more by say, sending one piece from a stack to somewhere else and see what it does, but I’ve done enough for now. I don’t know what undo contributes. I leave this to others to dig through the code.