capital T in Task

Just noticed the 2 tasks I have in my main module end with:

Task.cont

but the one in my camera module ends with:

task.cont

in my main module I do have

from direct.task import Task	

but no task iport at all in the camera module (though obviously I import camera into main.

It all works though :slight_smile:. it kinda bothers me though, is it T or t?

That has nothing to do with the import, just how you name your variables. For example:

mytask = taskMgr.add(self.doTask, "myTask")

def doTask(self, task):
	(...)
	return task.cont

but:

mytask = taskMgr.add(self.doTask, "myTask")

def doTask(self, Task):
	(...)
	return Task.cont

When you start a task via add the function automatically receives the task variable which internally you can name however you want. If you want to pass extra variables and the task object, you have to explicitly state so:

mytask = taskMgr.add(self.doTask,  extraArgs=[1.0], "myTask", appendTask=True)

def doTask(self, number, task):
	print number
	return task.cont

The print should print 1.0. The add passes an extra argument as well as the task argument. Here the task argument comes last.

mytask = taskMgr.add(self.doTask,  extraArgs=[1.0], "myTask", appendTask=True)

def doTask(self, task, number):
	print number
	return task.cont

This should not work as hoped. Here the print statement will print something every frame when the task is executed. Print task.cont will fail because the passed integer has no cont variable.

See this one, where the function receives three kind of variables: One passed from the task add, one optional parameter and the task object:

mytask = taskMgr.add(self.doTask,  extraArgs=[1.0], "myTask", appendTask=True)

def doTask(self, number, trigger=2.0, task):
	print number
	return task.cont

thanks for the reply. The variable name explanation makes sense, but my code was running fine with this:

def taskAI(self, task):
...
    return Task.cont 

def taskMove(self, task):
...
    return Task.cont

and it worked fine. I have just changed the returns to

return task.cont

and it stills works . This makes more sense, but the fact that it worked with Task.cont makes me think somehow I was using the import object?

For historical reasons, the symbols “cont”, “done”, “again”, and so on are also defined at the Task module level, so you can access them via “Task.cont” if you have imported the Task module at the top of your file.

However, the preferred way to access them is as members of your task object, e.g. “task.cont”.

David

thanks for clearing that up. It was just bugging me that Task.cont worked also :slight_smile: