a task question

OK, so:

import direct.directbase.DirectStart
from pandac.PandaModules import *

def textTask(task):
	print task.frame
	return task.cont

taskMgr.add(textTask, 'Task Name')

run()

Works fine, but when I do:

import direct.directbase.DirectStart
from pandac.PandaModules import *

def textTask(task):
	print task.frame
	return task.again

taskMgr.doMethodLater(1, textTask, 'Task Name')

run()

I get 0 in the console each second. Why?

task.again tells the task to be re-ran with the same time delay. This is like telling it to stop, wait for 1 sec for the next frame, and then redo it again a new.

This means theres no frames in between the call. The same can be said for calling task.time.

Oh, so thats how its designed.
OK, I guess I’ll just do

import direct.directbase.DirectStart
from pandac.PandaModules import *

x = 1

def textTask(task):
	global x
	
	x += 1
	print x

	return task.again

taskMgr.doMethodLater(1, textTask, 'Task Name')

run() 

Is this only abstracted example code or are you really trying to measure time with a task? there are better ways to do that, you know. Like using the time module or GlobalClock, for example.

I’m not trying to measure time with a task. Indeed that would be weird, just want to remember how many times the doMethodLater task has been run.
The task.frame works for normal tasks when using task.cont.