getting the object name having the nodepath

A bit noob question, I guess :blush:
The enemies in my game are all instances of the Enemy() class; they are enemy1 = Enemy(), enemy2 = Enemy(), enemy3 = Enemy() and so on. While the player is another class.
When I shoot at enemies, I can get a nodepath of the enemy. How can I find out which enemy instance does it belong to (whether it is enemy1, or enemy2 or some other enemy)?
(I think it’s more Python-related question then Panda-related…)

Looking at how you do it, the easiest way is using setPythonTag, and setting the Enemy object. Like:

enemyNodePath1.setPythonTag("enemyObject", myEnemyObject)

Later, you can then acquire the enemy object, like:

myEnemyObject = enemyNodePath.getPythonTag("enemyObject")

That should work. I’m using something similar in my game.

But, another advisable way is to store your enemies in a list:

enemies = []
enemies.append(Enemy("first enemy"))
enemies.append(Enemy("second enemy"))
enemies.append(Enemy("third enemy"))
enemies.append(Enemy("fourth enemy"))
enemies[0].doSomething()
enemies[3].yadda yadda

Then, you only have to store an enemy ID in the python tag:

enemyNodePath.setPythonTag("enemyIndex", 2)
#blah dee blah
myEnemy = enemies[enemyNodePath.getPythonTag("enemyIndex")]

Thank you! I’m going to try right now.