endObject is deleting all objects with the same name.

I’m trying to finish up my logout function in my game but when my client recvieces the data that uses has logged out it removes all player objects instead of just the one I selected it to end.

It works something like this:
When a new player logs into the world.

for name in state:
                            if not name in self.entities:
                                scene = logic.getCurrentScene()
                                entity = scene.addObject("Player", "SpawnLoc")
                                entity.children[0]["Text"] = name
                                self.entities[name] = entity
                                entity = self.entities[name]

entities is a dictionary that holds all the “Player” entities that have logged into the world and it works as intended. It should have a new object for each entities (as far as I know).

When I get ready to logout the server sends out which user is logging out. Then I do this:

if buf[1] in self.entities:
                            print("Player logged out: " + buf[1])
                            print("No such player is logged in.") 

The keys in entities are the name’s of the players so buf[1] = logged out player name. The odd thing here is the player has a single child which is a text object to just display a name for now, the name is left for all the players that didn’t logout but the actual “Player” model is removed.

Any idea what could cause this? I’m guessing it’s a mis-understanding how the game objects are created but if that’s the case how could I make a work around?

Are you sure that each player is being assigned a unique name when they login?

Yup, when logging in you have to input a user name. The names are also displayed over the top of each Player object.

I don’t think the problem is in the code that you have posted. In your log-out code, where does ‘buf[1]’ come from?

When you logout, you say that the text stats in the game but the player models disappear? That is funky because endObject() ends the current object and all its children. It seems like something is happening to the models or meshes of the player’s besides them being deleted. Do you do any tricks with visibility of the models or anything?

Naw, I don’t have anything fancy as far as the graphics go at all. The Player object is just a small plain and the text is the plains child. The objects get moved by a script run on the camera(atm), the text is updated by the first login packet which assigns the name to the entities dictonary and the child text object.

I think you will have to post more code or your .blend file if you want more forum help. If you are not doing anything with the visibility of the players then something else is happening that is causing the issue.

No telling, posting the blend files would take forever to go thru all the code. I’m just gonna assume it’s something weird with how the endobject method works and figure something else out. Thanks

That’s fine. I think it is very unlikely that you have encountered a bug in ‘endObject’ unless you are using a custom build of Blender and have modified it yourself. You should add some debug statements to dump out more data to see if all the objects really are being removed from the system or if something else is happening to them.

For example, after a logout happens, print out the number of objects still present in the scene.