Python, sockets and the Game Engine!

I’ve been playing with the game networking tutorial in the 2nd edition of the Blender GameKit and I found out that in it’s current form, it does not work. After banging on it for a bit, I had seperate scripts for the Game Engine working, a and a with a couple of default values that I had thrown in.

After getting a couple instances of Blender talking to each other (on the same machine for the time being), I felt that it would be better if everything was in one script, and seperate functions were called when needed. That’s what I’ve done, as far as client/server setup and passing data. 🙂

Right now the updateData function only passes location data for two objects, OBClient and OBServer. To use this script in it’s current form , two files will need to be created: server.blend and client.blend, where both objects will need to be present. On each object, there are three sensors required, one always that triggers once, an always that triggers constantly, and a spacebar keyboard sensor.

The always sensor that triggers once is set to run the “universal_networking.networkInitServer” or “universal_networking.networkInitClient”, depending on which one you’re wanting to run. The constantly-triggered always sensor is set to run “universal_networking.updateData”, which exchanges object location data with the other party. The spacebar sensor will need to make it’s way to a Motion controller, where the object is moved in some fashion.

When dealing with connecting the spacebar, only one will need to be connected on each file. For example, on the server.blend file, only OBServer needs to have the spacebar sensor moving anything. Vice versa with the client.blend file.

I’ll be updating this script once I have a method for properly moving different types of data across. For now, enjoy!



Leave a Reply

Your email address will not be published. Required fields are marked *