Our first take at creating a multi-player, networked game will be done by starting with a sample chat client/server code base (included in Luke Escude's tutorial) and adding more functionality to it.
In the chat console, we have added a walled region where a user can move a character (using the arrow keys) around and see other characters who are in the chat room.
We designed the workflow for how this would be accomplished and then implemented the code. After walking through the code at least 5 times, we ran it and it worked... sort of. I was using writebyte() for sending the tcp id and the x,y coordinates for the characters and the x,y max values well exceeded the value 256, which is the maximum numeric value that can be represented with a byte. That accounted for the strange behavior we were seeing -- the user could see their own character bounded in the walls, but the other characters were outside and to the left. Furthermore, the other characters would suddenly jump to the left side of the screen when their owners moved too far to the right.
I couldn't find logging functions in GameMaker (well, there is an error logging method, but I wasn't logging errors), so I created my own using GM's file and time methods. I used the resulting log file to help me better see what was going on. Along with helping me locate my 'byte' issue, I also realized some extra looping that I want to get rid of.
The solution in fixing the 'byte' issue was to change those particular writebyte()/readbyte() calls to writeint()/readint(). Since my game board is no bigger than 640 x 480, integers are all that I will need.
While debugging the code, I found myself wishing there were better debugging tools. Perhaps I don't yet know how to take better advantage of the debug mode in GM; I found my code walk-throughs and the new logging capability to be more useful so far. I also like putting my source code under source control, but since the scripts are all inside a GM file, I don't get the full advantage I would like. It would be nice if there was a way to export all scripts, no matter where they showed up, and to likewise import all scripts from a directory of files. That way I could easily see where changes were last made. Perhaps there is a GM function that can be used to do this and I simply don't know about it yet.
No comments:
Post a Comment