BGEM send

Is it possible to do so that not only the position was sent, but also the orientation?
server


def send(self):     
 scene = logic.getCurrentScene()
      
        statp= {(gobj.name, gobj["user"].name): list(Vector(gobj.worldPosition))
            for gobj in scene.objects
            if gobj.name== "pl"}   
                            
        for addr in self.addr_user:

            self.socket.sendto(pickle.dumps(statp), addr)

client

  def receive(self):        while True:
            try:
                data, addr= self.socket.recvfrom(1024)
                state = pickle.loads(data)


                for k in state:
                    if not k in self.entities:
                        scene= logic.getCurrentScene()
                        spawner = scene.objects["Spawner"]
                        smap = scene.objects["Smap"]
                        entity = scene.addObject("pl", spawner)
                        entity.children[0]["Text"] = k[1]
                        self.entities[k] = entity
                    else:
                        entity = self.entities[k]

                    entity.worldPosition = Vector(state[k])

Orientation can be get with obj.worldOrientation

I know, I need to send worldOrientation and worldPosition together.

theres indenting errors, syntax errors, while loops, creating vectors of vectors to make a list, and the scariest one:

a tuple for the dict key… :eek:

how does this even work?

So you need to combine the data to make a single “packet” to send. You can do this by packing things into a list/tuple/dict:


packet = {}
for obj in scene.objects:
    if obj.name == "pl":  # You can actually do scene.objects["pl"], but whatever
        data = {}
        data["pos"] = list(obj.worldPosition)
        data["rot"] = list(obj.worldOrientation.to_euler())
        packet[obj.name] = data

for addr in self.addr_user:
    self.socket.sendto(pickle.dumps(packet), addr)

Then after recieving and de-pickling, you should get a dict containing lists of the position and rotation

a tuple for the dict key…

how does this even work?

I don’t think this is what’s happening here, but tuples work well as dict keys. This is quite standard and it works because a tuple is immutable, and so it’s hash value will always be the same.

Thanks for the activity, everything works))