我正在使用此代码向 Pure Data 发送信息,在 Python 控制台中我看到了两个不同的变量,但是 Pure Data 不断接收它们,而不是作为两个单独的数字相加。
import bge
# run main program
main()
import socket
# get controller
cont2 = bge.logic.getCurrentController()
# get object that controller is attached to
owner2 = cont2.owner
# get the current scene
scene = bge.logic.getCurrentScene()
# get a list of the objects in the scene
objList = scene.objects
# get object named Box
enemy = objList["enemy"]
enemy2 = objList["enemy2"]
# get the distance between them
distance = owner2.getDistanceTo(enemy)
XValue = distance
print (distance)
# get the distance between them
distance2 = owner2.getDistanceTo(enemy2)
XValue = distance2
print (distance2)
tsr = str(distance + distance2)
tsr += ';'
host = '127.0.0.1'
port = 50007
msg = '123456;'
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
s.send(tsr.encode())
s.shutdown(0)
s.close()
我需要发送最多 10 种不同距离的物体,这与寻找与敌人的距离有关