picking multiple objects (again)

hey, i´m here again. my question is not more about collisions, but about nodepaths. i´m trying to pick objects with different names, but in the task i don´t now how to specify them. take a look i´m my code(it´s an example).


#LOAD MODELS
for i in rage(10):
  self.piece1[i] = loader.loadModel("models/piece1")
  self.piece2[i] = loader.loadModel("models/piece2")
  self.piece3[i] = loader.loadModel("models/piece3")
  self.piece4[i] = loader.loadModel("models/piece4")

#THE TAGS AND BITMASKS IS SPECIFIED TOO
self.i = 1

#THE EVENTS
self.accept('1', self.new1) 

def new1:
  piece1[self.i].reparentTo(render)
  self.i +=1
# and there has an accept and def for the pieces 2,3 and 4

#NOW THE PROBLEM WITH THE TASK (like the picking tutorial)
def MouseTask(self, task):
  self.pieceX[self.dragging].setPos(PointAtZ(.5, nearpoint, nearvec))

that is it. what i need know is what i need to put in the self.pieceX to allow me to pick the different objects (1,2,3 or 4).
hard to describle, huh?

Hey kutz,

I’m trying to figure out what you are trying to do here.

If you are trying to find a way to specify piece1, piece2, etcetera, there’s a few different ways:


num=2
object=getattr(self,"piece%i"%num,None)
#the None is returned if the attributed doesn't exist
if(object):
    #do stuff on object as if it were pieceX

On the otherhand, you might be looking for something else entirely.