Im working on a game, and I struggle on how to get object names from another layer in python. If so can you tell me how?
First of all! Hello there K1mberly! And welcome to this little corner of the internet : D
Now, let’s see… object names from another layer… that sounds very strange to me
What are you trying to do? Why do you need to get the object names from another layer?
Are the names not accessible before you run the game?
Looking forward to seeing your works and demos! Cheers! Ø__^
wrong forum section…
Anyway:
obj = own.scene.objectsInactive['object name that is on hidden layer']
to create a list with all objectts from inactive layer
objects = [obj for obj in own.scene.objectsInactive]
You can not get a list “from another layer” directly. As Cotaks says, you can get a list of objects only from a hidden layer or all object in the scene.
If you want the list of objects on a specific layer you have several options:
- Parent all objects in that layer to one base object and then get its children
- Group all objects in that layer in 1 group, then access the group and get it’s members - “obj.groupmembers”. But the group object have to be dupli group instance containing all object in that layer.
- Add a custom property to each object in that layer e.g. - “layer3Obj” and then get the list of all objects in the scene and filter only “layer3Obj” in that list.
- If objects in that layer are dynamically added then on their creation you have to add the above property to each newly created object and then access them like in 3 point.
If your game needs to manage constantly specific objects on different layers, probably you will have to create some sort of a manager that takes care of all objects of interest when game is running.
- Add objects in dictionaries with ID’s for key…etc. and then access the dictionaries and manipulate the objects there.
Thanks ya’ll I’m still a beginner in python in bge