Need Help

I need to create a counter that counts something in 1 minute. I tried but 60 second of the task doesn’t correspond with the real time
I have this code:
self.tempoMax = 60
taskMgr.add(self.trash[2].countTimer, “countTimer2”)
def countTimer(self, task):
if self.counter>=0:
self.counter -=1

    return Task.cont

thanks in advance

Indeed, tasks generally fire once per frame, not once per second, I believe.

However, using the global clock should allow you to find out how much time has passed and subtract that from your counter; it does, however, come with the risk of more time passing than you intend.

Otherwise you might try doMethodLater in place of a task.

Sorry, but the piece of code you posted doesn’t make any sense without all the classes involved.

On the other hand, would you mind describing what you want to archieve? Maybe there’s an easier way.

You can also use task.time to check how many seconds passed.

I think the best way is doMethodLater & task.again which execute your function every xx seconds

def my_action(task):
    return task.again

taskMgr.doMethodLater(60, my_action, 'my_action')

True – and in fact my usual method for doing this – I believe. However, I think that I recall seeing somewhere that the Global Clock is in some way preferable (I forget the specifics, I’m afraid ^^; ), and so thought it better to suggest that method.


thanks for your answers. it help me alot. it´s working as i wanted.

Thanks again,

pjan :smiley: :smiley: :smiley: