Thursday, June 11, 2009

Son of a b...

ene gesserit...

In programming a game like this, there are lots of times when you want to try and find out what cell the unit is in, or to make a comparison of some kind. In these instances you use a simple conditional based on coordinates, such as "If (UnitX = CellX) And (UnitY = CellX)", which will answer true if your unit is in the same cell you are asking about.

Did you see what was wrong with that statement? Because that's exactly the mistake I made a long time ago, only it was so particular I didn't discover it until now. After hours upon hours of debug trapping and testing, tons of seemingly illogical behavior, tracing the error all the way back to some potentially very complicated code, and a handful of expletives, it turned out to be a simple coding error. Nothing a machine or an analyzer could have prevented; this was all on me. I entered the X coordinates for the cell twice instead of the X and Y coordinates. This meant that, when a unit was in a cell that was on the diagonal line on the map that had matching coordinates (65,65 etc), an adjacent cell would be considered as wide open for travel, regardless of what was in it, because the system thought it was the very same cell the unit was in. I know, right?

I could expound much further on this but I'll save us all the headache. Suffice to say pathfinding will be fixed in the next bugfix version. Crashes may still remain but they won't have anything to do with this.