Tubutas
February 18, 2010, 3:44am
1
As mentioned numerous times before, I have programmed in many other languages, but I’m new to python. I’ve used other OOP languages before, but I’m not 100% sure on how python’s is supposed to work… That being said this is my code.
import direct.directbase.DirectStart
from direct.actor.Actor import Actor
class Cars(Actor):
def add(self):
self.reparentTo(render)#Line 6
self.top_speed=getTopSpeed()
self.acceleration=getAcceleration()
def getTopSpeed(self):
return 120
def getAcceleration(self):
return 20
class Taxi(Cars):
def __init__(self):
self=Actor("racingmodels/us_taxi")
def getTopSpeed(self):
return 150
def getAcceleration(self):
return 17
taxi = Taxi()
taxi.add()#Line 23
run()
The command line gives the error
DirectStart: Starting the game.
Known pipe types:
wglGraphicsPipe
(all display modules loaded.)
:Actor(warning): racingmodels/us_taxi is not a character!
Traceback (most recent call last):
File “C:\Users\Private Tubutas\Desktop\Tut\racing.py”, line 23, in
taxi.add()
File “C:\Users\Private Tubutas\Desktop\Tut\racing.py”, line 6, in add
self.reparentTo(render)
AttributeError: C++ object is not yet constructed, or already destructed.
adr
February 18, 2010, 4:10am
2
DirectStart: Starting the game.
Known pipe types:
wglGraphicsPipe
(all display modules loaded.)
:Actor(warning): racingmodels/us_taxi is not a character!
Traceback (most recent call last):
File “C:\Users\Private Tubutas\Desktop\Tut\racing.py”, line 23, in
taxi.add()
File “C:\Users\Private Tubutas\Desktop\Tut\racing.py”, line 6, in add
self.reparentTo(render)
AttributeError: C++ object is not yet constructed, or already destructed.
At line 6 you just have “self.reparentTo(render)” but you have no model to reparen it to the render… aka you’ll need something like… “self.base.camera.reparentTo(render)” to get it to work. Base.camera is your model/node.
drwr
February 18, 2010, 4:56am
3
Note that your class inherits (indirectly) from NodePath, but then defines its own constructor and doesn’t (properly) call up to the parent constructor. This means your base NodePath class was never initialized, which is what is triggering this particular error message.
When you define a constructor, you should generally always call up to the base class constructor, something like this:
def __init__(self):
Cars.__init__("racingmodels/us_taxi")
Note also that assigning self does nothing. It doesn’t change the instance to a new Actor.
David
Tubutas
February 18, 2010, 5:13am
4
Im not exactly sure on how this works. taxi=Taxi() doesn’t create a new actor? and I have to call the parent’s init function manually?
This might just be the worst OOP language ever. :O.
Can someone show me the orthodox method of doing what I’m doing?
[edit]
What does this message mean?
[Edit 2]
This code got it work
import direct.directbase.DirectStart
from direct.actor.Actor import Actor
class Cars(Actor):
def __init__(self,stance):
self.base=Actor(stance,{"stance":stance})
def add(self):
self.base.reparentTo(render)
self.base.top_speed=self.getTopSpeed()
self.base.acceleration=self.getAcceleration()
def getTopSpeed(self):
return 120
def getAcceleration(self):
return 20
class Taxi(Cars):
def __init__(self):
Cars.__init__(self,"racingmodels/us_taxi")
def getTopSpeed(self):
return 150
def getAcceleration(self):
return 17
taxi = Taxi()
taxi.add()
print taxi.base.top_speed
run()
Tubutas
February 18, 2010, 6:31am
5
Found this post
discourse.panda3d.org/viewtopic.php?t=6714
And I went through and deleted all the blend’s and it fixes that little, not a character bug.