Name 'worldNP' is not defined

Hello everyone,

I am trying to get an answer on Stack Overflow towards this issue. So far, nobody was able to answer this question. I decided to ask here since this is a forum for Panda3D.

Full details are in the provided hyperlink. In short, I am trying to do character movement from the provided code example on Panda3D’s manual towards their Bullet Physics engine. I have gotten a world set up, but it throws me an error about worldNP. I have not went through the entire document, but a quick search indicates that worldNP is only dealt with their Bullet Physics engine.

Hi and welcome.

You are mixing paradigms in your code and it isn’t complete.

self.worldNP is never defined and self. would imply that it would be a member of a class. You are not defining this inside a class, so the self. part shouldn’t be there. Also you have to define the NodePath that holds your physics world (that is that missing worldNP) and attach it to the scenegraph (usually the render node).

All that is explained in the manual, try to read through the manual carefully and also try to brush up on your Python skills.

To elaborate a little on what tcdude said above, “self” is the conventionally-used name for a special parameter that’s automatically passed into methods belonging to instances of classes. It stores a reference to the instance, allowing the developer to access the variables and methods of that instance.

For example:

# A simple class.
# Note the use of the "self" parameter below.
class Cat():
    # The initialisation method
    def __init__(self):
        self.sound = "Meow"

    def mew(self):
        print (self.sound)

cat = Cat()
# Note that the "self" parameter is >not< passed in above!
# It's automatically provided, since this method is being called
# from a class-instance.

Looking over the manual pages, it does look as though they indeed don’t clarify where “worldNP” comes from, which may confuse those not already familiar with object-oriented Python. Those pages could perhaps use some touch-ups to make them clearer, I think.

Thank you @tcdude. Your explanation have led me to investigate more about self.worldNP. I was able to get worldNP to work by defining what shape the world is. For anybody else that is having the same issue, I wrote the following code when doing world declaration:
Imports -

from panda3d.core import Vec3
from panda3d.bullet import BulletWorld
from panda3d.bullet import BulletBoxShape
from panda3d.bullet import BulletRigidBodyNode

Within the class initalization. Game(ShowBase) for example:

       = BulletWorld()
      , 0, -9.81))
                shape = BulletBoxShape(Vec3(30, 30, 30))
                node = BulletRigidBodyNode('World')

                self.worldNP = render.attachNewNode(node)

Thanks for elaborating on how self. is used. On the side side, I am thankful that I am not the only one that thinks for that particular section in Panda3D manual did not discribe about worldNP.