I have problem with python script in game engine. That script running OK (I see it in console), but Game engine freeze.
Does anybody knows where the problem is?
thaks for any help
HOST = ‘localhost’
PORT = 8778
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
cont = GameLogic.getCurrentController()
own = cont.getOwner()
bone = GameLogic.getCurrentScene().getObjectList()[“cube”]
data = s.recv(4096)
b = string.find(data, “X=”)
c = string.find(data, “_”)
P = data[b+2:c]
X = float§
d = string.find(data, “Y=”)
e = string.find(data, “_Z”)
Y = float(Q)
f = string.find(data, “Z=”)
g = string.find(data, “_end”)
Z = float®
When do you think this loop would stop looping?
I need continual data flow. Do you think that I have to use another type of cycle?
If you trigger the script through the regular gamelogic python controller and have the sensor set to allways, the script will rerun automaticly for every frame… so no need to loop.
Now your script just loops internally on the first frame… so the game has no chance to progress.
Scripts in BGE have to finish as soon as possible, because BGE waits for them. And you have infinite cycle inside the script, so it never finish and so BGE cannot continue.
Another problem is that recv() blocks processing of script until it receives some data. So it can also cause lagging, even if server sends data constantly. You can use socket’s method setblocking() to change this behaviour.