How do I use taskMgr.add?

so I added taskMgr.add(self.update, “update”)
then I defined update
def update(self, task):

And then when I run the pgrm it says something like “attribute error attribute update does not exist.”
Update is a method.

I’m guessing you defined update() outside the scope of whatever class is calling taskMgr.add(), but I can’t be sure unless you post the bit of code that causing the problem. Could you do that please? :slight_smile:

yeah, I agree

here is a simple print task with proper indent:

import os
import sys

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.showbase.DirectObject import DirectObject
from direct.task.Task import Task

class World(DirectObject):
  def __init__(self):
    self.mainLoop = taskMgr.add(self.update, "update")

  def update(self, task):
    print "update"
    return Task.cont       # Continue the task indefinitely

w = World()
from direct.showbase.ShowBase import ShowBase
from panda3d.core import *
from import Actor

#the limit is -140 and 157

class Application(ShowBase):
    def __init__(self):
        self.stage = loader.loadModel("stage")
        self.protag = loader.loadModel("handandgun")

        self.taskMgr.add(self.out_of_bounds, "out of bounds")


        self.accept("w", self.walkup)
        self.accept("a", self.walkleft)
        self.accept("s", self.walkdown)
        self.accept("d", self.walkright)

        def walkup(self):
            self.protag.setY(self.protag, -.2)

        def walkleft(self):
            self.protag.setX(self.protag, -.2)

        def walkdown(self):
            self.protag.setY(self.protag, .2)

        def walkup(self):
            self.protag.setX(self.protag, .2)

        def out_of_bounds(self, task):

            if self.protag.getX > 157:

            if self.protag.getX < -140:

        return task.cont

def out_of_bounds needs to be tabbed out right?

Edit: I tried these and panda 3d gave me:

Known pipe types:
(all display modules loaded.)
:display(error): The application requested harware acceleration, but your OpenGL
:display(error): driver, GDI Generic, only supports software rendering.
:display(error): You need to install a hardware-accelerated OpenGL driver, or,
:display(error): if you actually want to use a software renderer, then
:display(error): alter the hardware/software configuration in your Config.prc file.
:ShowBase(warning): Unable to open ‘onscreen’ window.
Traceback (most recent call last):
File “C:\Users\Lisa\Documents\NetBeansProjects\Zombie_Arena\src\”, line 10, in
gameApp = Application()
File “C:\Users\Lisa\Documents\NetBeansProjects\Zombie_Arena\src\”, line 11, in init
File “C:\Panda3D-1.7.2\direct\showbase\”, line 243, in init
self.openDefaultWindow(startDirect = False, props=props)
File “C:\Panda3D-1.7.2\direct\showbase\”, line 765, in openDefaultWindow
raise StandardError, ‘Could not open window.’
StandardError: Could not open window.

It’s unusual to inherit from ShowBase and init it. Mostly people will inherit from DirectObject and init that.
To grab a window people usually do

import direct.directbase.DirectStart

Maybe it could work the way you do it, but there’s propably a reason why you never see people do it.

Also, never do a

from panda3d.core import *

You will quickly lose track of what you actually imported and transfer way too much into your namespace.

Actually I believe inheriting from ShowBase is now the recommended method and is what is used in the manual.

If you’re making a simple example, test, or demo program, using DirectStart is fine. (You could even use it for full games)

If you’re following an OO approach, which most people prefer, then inherit from ShowBase.

Using a

from panda3d.core import *

is also perfectly okay.

import * is there for a reason, when you want to import everything. If namespace clutter is a problem for you, then simply never use an *, and specify modules individually.

Also, there is little to no performance loss for importing everything (*) vs importing things individually.

Hope this helps,


everything looks like it’s inside of init, maybe you don’t want to do that; also the return in the def out_of_bounds looks like it is not tabbed in where it should be inside of def out_of_bounds