Basic Problem: Passing reference to get attributes

Hi there,

New Panda3D user, still getting the hang of it.
My basic code is:

#all the import stuff

class MyApp(ShowBase):
    def __init__(self):

        #initialisation modules = self.loader.loadModel("models/slacker"), 0.025, 0.025),0,0)

class Hello(DirectObject.DirectObject):
    def __init__(self):
    def printHello(self):
        print "Hello"

h = Hello()
app = MyApp()

What I would like to do is be able to have the “slacker” model print its location when I click on the screen.
In an earlier version of the code I did it in the MyApp method to see if it worked:

self.textObject = OnscreenText(text = 'Man is' + str(, pos = (-0.5, 0.02), scale = 0.07)

But that happened on initialisation.
I am not sure how I can have the event manager listen out for a mouse click and then access to the methods/attributes in “man”. I’m still getting my head around how I can have all these different class references all link to one another or if everything/most things are intended to happen in MyApp.

I messed around trying to have self.accept(‘mouse1’, event_name(object_reference)) in the MyApp code and then the Hello class would then have access to it, but it always said the command didn’t exist (so I figured because it appeared lower, it couldn’t “see it”) but then it didn’t seem possible to reorganise the code.

I read the Task and Even Handling manual but it wasn’t really clear on this point, so I was hoping for some “human” clarification on this if possible.


In order to pass arguments to a method you call with the event handler, you would structure it something like this

self.accept("mouse1", self.printData, [])

And then have

def printData(self, nodepath):
    print "The man is at {}".format(nodepath.getPos())

Whenever you write something like method(args), python will immediately stop whatever it’s doing and run that method to find out what value it is. If you don’t specify a return value in the method, it will default to None. This is what panda3d was probably complaining about. According to the directobject class, you called self.accept(“mouse1”, None).

So when you need to pass a method and its arguments to some other piece of code (like you’re doing now), you need to pass the args along as a standalone list so that the method is not executed. Panda3d has provided an extra argument you can submit to accept called extraArg so that you can do this.

I have just messed around with it and I got it to work.
I didn’t know about the last parameter being available.

Thanks so much.