rookie mistake

Hi. blown away by panda3d’s potential. just awesome. and its great for me to use while getting to grips with python. been a very fun month.

anyway, i am having a little difficulty creating a range of cubes (linked to bullet nodes) using a loop and then referencing them after creating them.

he creating i can do, but how do i reference these cube and do things like getPos/setPos them using a for loop?

even when i try and print them using the loop i just get none, none, none, etc

any help or direction appreciated :slight_smile:

the code snips i am using are:

 def makeBlocks(self):
          numBlocks = 5 + int(random.random()*5)
              for i in range(numBlocks):
          for i in range(numBlocks):
              print (self.blocks)

and the code for makeCube(i) is

def makeCube(self,num):

          shape = BulletBoxShape(Vec3(0.5,0.5,0.5))
          nameNP = self.worldNP.attachNewNode(BulletRigidBodyNode("cubeX"))
          nameNP.setPos(-4+(random.random()*8), -1,10)

          nameCube = loader.loadModel("box.egg")
          newTexture = loader.loadTexture("whiteTexture.png")

I believe your problem is that makeCube isn’t returning anything. Try adding

return nameNP

as the last line of the function.

After that your print loop should be fine, and you should also be able to do things like



thanks for the replies.

Johan that solves the problem.

Luna, it’s there inside the 1st loop. self.blocks.append(self.makeCube(i))