Hi everyone, I’m a grad student working on using Panda3d to interface with a small manufacturing system.
I’ve been trying to use event handlers to run animations when certain events happen on the floor. I made a simple test to try to get the methodology to work but I can’t figure out the best way to do this. In the code below I load the models in a seperate function file called “smachine”(which I think is working because its loaded other models fine) but when I send the message it says:
Hello instance has no attribute ‘pandaActor’
In my smachine function all of my commands are preceded by “self.” So I change h=hello() to h=hello(self) and then I get:
init() takes exactly 1 argument (2 given)
I just want to conditionally start animations for meshes that are initially present but motionless. How should I go about this?
from pandac.PandaModules import Vec3,Vec4
from direct.gui.OnscreenText import OnscreenText
from direct.showbase import DirectObject
from pandac.PandaModules import *
import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from direct.task import Task
import smachine
import spin
class world (DirectObject):
def init(self): #-------------------------
class Hello(DirectObject):
def init(self):
self.accept(‘mouse1’,self.printHello)
def printHello(self):
print ‘message recieved!’
self.pandaActor.loop(“walk”)
The Python convention is that when any method is called, even the constructor, “self” is implicitly passed as the first argument. Thus, the call:
h = Hello()
Actually calls the method with the prototype:
class Hello:
def __init__(self):
and the first parameter is implicitly passed with the value of the newly created Hello instance. It would be a mistake to attempt to pass a second parameter to the Hello constructor.
As to your particular problem, well, I don’t see your Hello class assigning anything to self.pandaActor, so it’s hardly a surprise that it isn’t assigned. What did you expect to find in self.pandaActor? Looks like you were copying and pasting code from some other source, but you copied only the part that references this member, and not the part that declares it.
Incidentally, when you paste Python code in the forums, please use the code tags to preserve indentation. Without this, it is hard to read the code.
Thanks for your reply. Your right I am new to python, I appreciate your patience. I loaded the panda actor in a separate function called smachine in a separate file. I use this code to do it:
def layout(self):
#Load the panda actor, and loop its animation
self.pandaActor = Actor.Actor("models/panda-model",{"walk":"models/panda-walk4"})
self.pandaActor.setScale(0.005,0.005,0.005)
self.pandaActor.reparentTo(render)
I am trying to activate the walking animation in an event handler. I’m not sure what to send to the event handler so I can call the walking animation there without loading the model there. This is the code from the original panda demo. I’m just trying to see how I would control animations.
So you should understand that “self” refers to this particular instance; it is not a global value, and it is not the same thing in every method. So when you say “self.pandaActor = blah blah blah” in one object, you are assigning the pandaActor member of that particular object. If you later reference “self.pandaActor” in a different object, it’s a different member, and if you haven’t assigned it in that object, it doesn’t exist.