Help with physics ID

Ok I have been working on an inventory script that allows you to spawn in containers. People is that the dictionary holding the inventory is on the items properties and I need to find a way to call the physics ID of the new spawned container so I can locate it in another scene… I know how to get the ID using own.getPhyisicId() but how do I do something like scene.objects[physics ID]… So I can get the property inventory?

if you have the game object (not its name)
you should be able to call it from another scene, I think*

when adding the item

added = bge.logic.getCurrentScene().addObject(‘yourObject’,own,0)

then send a message that is the game object to the other scene,
I am not sure if you can send it as a string and eval(string) or if you can send
a game object as a message property.

To get object from any scene, you need to get a list of available scenes


import bge

sceneAll = bge.logic.getSceneList()
scene = sceneAll[x] 
obj = scene.objects['y']

No that is not the proplem I need to get a property from an instanced object… So I need the ID to get it

Your question doesn’t really make a lot of sense at the moment.

Why do you need the physics ID, for a constraint? If not, then don’t use the physics ID. You can find GameObjects (and other types) in the BGE scene object list using scene.objects.from_id(), passing in the python id() of the object.

However, I can’t think of a use case where you would not be able to store a python reference. Perhaps, if you’re sending the id using message actuators, that would make sense, but only slightly. It makes more sense for the containers to register themselves to globalDict, or a manager object which is exposed to global dict.

OK sorry if wasn’t clear… I have a cube who’s name is chest. It has a property called inventory. I want to be able to spawn (let’s say 5) of theses cubes and be able to add and remove items from each of these “chests”. My method was to send the name of the interacted cube to the global dictionary to be used in a separate scene… Here is were the problems start… All the spawned cubs have the name chest… The cause if I remember right is that the added object is instanced into the game. So I have heard that you could get the physics ID of the object and use that ‘find’ the object on a separate scene.

just store the chests as a list when you add them,

the object not the name

addedChest= bge.logic.getCurrentScene().addObject(‘chest’,own,0)

Just thinking out loud… Can I set and object to a property? Like the refrance to the object… I should be able to because the properties are just a list on the object. Correct?

you can even store a list as property,

You can get a GameObject by reference from its python Id, not physics id. Or you can store the object reference directly in a game property. Or, have the chest register itself into globaldict when it’s created

Sent from my SM-G920F using Tapatalk