Task error [Fixed]

Hello again,

I’ve been using tasks without a problem until all of a sudden one of mine “broke”. Its the exact same form as it was before and as numerous working ones, so I’m rather confused. Error:

self.taskTimer = taskMgr.add(self.timer, 'gameToolsTimer')
  File "C:\Panda3D-1.5.4\direct\src\task\Task.py", line 571, in add
    'add: Tried to add a task that was not a Task or a func')
  File "direct\src\directnotify\Notifier.py", line 130, in error
StandardError: add: Tried to add a task that was not a Task or a func

Code of the task:

def timer(self, task):
        dT = min(task.time - self.taskTimerTime, self.maxDT)
        self.taskTimerTime = task.time
        self.timer += dT
        
        for ob in self.timered:
            ob.timer += dT
            
        return task.cont

This handles whether the task is running:

def doTimer(self, value):
        if value:
            if not taskMgr.hasTaskNamed('gameToolsTimer'):
                self.taskTimer = taskMgr.add(self.timer, 'gameToolsTimer')
                self.taskTimerTime = 0.0
        else:
            if taskMgr.hasTaskNamed('gameToolsTimer'):
                taskMgr.remove(self.taskTimer)
                self.taskTimerTime = 0.0

And just for completeness the error occurs when I call:

self.doTimer(True)

As always, thanks for the help.

Thaago

Uh, you have both a variable named self.timer and a function. You should really give them different names (in fact, a function is a variable, so if you define “def timer” self.timer will point to that function. Because you set self.timer afterwards, you overwrite that function again with the variable.)

Oh wow, I can’t believe I didn’t catch that… :blush: I was adding the timer function and completely forgot… yeesh.

Thanks, and fixed.