TypeError: 'module' object is not callable?

Sorry to do this people, but I’ve run into another snag. You see, I decided to expand upon my keyboard camera code to include keyboard controls for an animated actor.

But I’m getting this error whenever I try to run it (I’ve made sure that all the relevant models are in the MODELS folder in the same directory that I’m running the script from):

Here is the code itself if that’s of any help (I’m using Panda3D version 1.0.5):

# KeyboardControls.py
# Controls are w - walk forward, s - walk backward,  a - turn left, 
# d - turn right. The arrows control the camera. 

import direct.directbase.DirectStart # Start Panda
from pandac.PandaModules import* # Import the Panda Modules
from direct.showbase.DirectObject import DirectObject # To listen for Events
from direct.task import Task # To use Tasks
from direct.actor import Actor # To use animated Actors 
from direct.interval.IntervalGlobal import * # To use Intervals
import math # To use math (angles, degrees..etc)
import sys 

class Controls(DirectObject):
    #Constructor
    def __init__(self): 
       base.disableMouse() # Disable default camera.
       self.speed = .05 # Controls speed of rotation and zoom.
       self.loadModels() 
       # Setup key controls
       self.accept("escape", sys.exit)
       self.accept("arrow_left", self.cameraTurn,[-1])
       self.accept("arrow_right", self.cameraTurn,[1])
       self.accept("arrow_up", self.cameraZoom,[-1])
       self.accept("arrow_down", self.cameraZoom,[1])
       self.accept("w", self.walk,[-1])
       self.accept("s",self.walk,[1])
       self.accept("a", self.turn,[-1])
       self.accept("d", self.turn,[1])
       # end __init__

    def loadModels(self):
        # Load the player and its animations
        self.player = Actor("MODELS/panda-model",{"walk":"MODELS/panda-walk4"})
        self.player.reparentTo(render) # Make it display/render on the screen.
        self.player.setScale(.005)
        self.player.setPos(0, 0, 0) # Position it at the center of the world.
        #Create a camera dummy node
        self.camera_dummy_node = render.attachNewNode("camera_dummy_node")
        #Position the camera dummy node
        self.camera_dummy_node.setPos( 0, 0, 0)
        # Attach the camera dummy node to the player.
        self.camera_dummy_node.reparentTo(self.player)
        # Attach the camera to the dummy node.
        camera.reparentTo(self.camera_dummy_node)
        # Position the camera
        camera.setPos(0, -30, 5) # X = left & right, Y = zoom, Z = Up & down.
        camera.setHpr(0, 0, 0) # Heading, pitch, roll.
        camera.lookAt(self.player)
        # end loadModels
    
    # Define the CameraTurn function.
    def cameraTurn(self,dir):
        self.camTurn = LerpHprInterval(self.camera_dummy_node, self.speed, Point3(self.camera_dummy_node.getH()-(10*dir), 0, 0))
        self.camTurn.start()
        # end cameraTurn
    
    # Define the cameraZoom function.
    def cameraZoom(self,dir):
        self.camZoom = LerpPosInterval(camera, self.speed, Point3(camera.getX(), camera.getY()-(2*dir), camera.getZ()))
        self.camZoom.start()
        # end cameraZoom
        
    def walk(self,dir):
        dist = 5.0
        angle = self.player.getH()*math.pi/180
        dx = dist*math.sin(angle)
        dy = dist*math.cos(angle)
        playerWalk = Parallel(
                             self.player.posInterval(1.0,Vec3(self.panda.getX()+dx,self.panda.getY()+dy,0)),
                             self.player.actorInterval("walk",loop=1,duration=1.0)
                             )
        playerWalk.start()
        
    def turn(self,dir):
        playerTurn = self.player.hprInterval(.2, Vec3(self.player.getH()-(10*dir),0,0))
        playerTurn.start()
        
# end class Controls

c = Controls()

run()

I’ve gone over and over it, but it looks almost identical to the tutorial that I’m working from. Maybe a fresh pair of eyes can see what I’ve done wrong. Any advice is most welcome.

Cheers

Hmm thats strange if you use

from direct.actor import actor

you are importing a Module named Actor
To use the actor class you have to use

Actor.Actor

self.player = Actor.Actor("MODELS/panda-model",{"walk":"MODELS/panda-walk4"})

Martin

Thankyou Martin, that fixed it. Where would I be without you :unamused:?

I’m following the BVW tutorial, and it uses:


self.panda = Actor("panda",{"walk":"panda-walk"})

I guess things have changed a little since that tutorial was written sigh life is very hard for newbies.

Thanks again.