So, I’m still hard at work on Puzzle Runners. Remember when I said that I had written the single player version in a way that lent itself easily to being converted over to multiplayer?
Yeah, I’m not as smart as I thought. It took 17.5 hours spread over many days to get the setup and sync working.* Or at least working well enough that I could move onto the ingame message handling, I still need to go back to the setup code and handle some loose ends.
So… the whole game is setup using a “bounce” server which just bounces all the messages it receives to all the connected clients. The first client to connect becomes the ‘Master’ which is responsible for setting up the game and owns the AIs. And now I’ve got an error state where if only the Master is connected, the AIs behave correctly, but if there are two or more clients the AIs just stand in place.
This is my code which dispatches messages to the server:
Here’s the crazy part… that “trace” statement marked with the red arrow? All it does is print the message being sent to the server to the debugging console (or copies it to a log file). I added it because I wanted to make sure the AI messages were being sent (they were). If the trace statement is present, the AIs move correctly. If the trace statement is commented out**, the AIs don’t move. Human players however, move correctly regardless of the presence of the trace, so I know the dispatch function is working.
Ultimately of course, the lack of a trace can not be the reason why the AIs are turning themselves off… I’m guessing the trace is affecting the timing in which the messages are being received and that’s causing something I didn’t intend (I designed the message handler to work regardless of the order in which messages are received, and independently of the refresh timer… but I’ve made bigger mistakes before! ).
Anybody reading this got a good story of a bug where the symptom and the root cause didn’t appear connected?
* – That’s not a complaint… I haven’t worked with multiplayer games before, so I’m turning up issues I’ve never considered before. (ie: How should the game react when a client disconnects before setup is complete? What should happen if a player attempts to join a table that’s already full? etc) So to the extent that I am a programmer, this is interesting stuff… it just taking longer than I had budgeted.
**- For the non-programmers, commenting out a statement makes the computer ignore it when it’s executing the program. The words following // are comments.