I’ll use in my game. My intention is, this timer runs when my player starts to fly. So I create a single method to add the
timer method in taskMgr. My doubt is: how can I do for timer method waits 2 seconds to decrement the total Time? I’ve think to use the
Wait() function. But I’ve seen in the forum that has a function in the taskMgr called doMethodLater that I can put the time in this function
and it waits to execute a function I determined. But my fear is when the seconds pass by the function will continues anymore. If the doMethodLater will continues to execute this infinitely, what’s the better approach to use? Wait or doMethodLater?
Sorry if I wasn’t clear. If you notice, my main questions are timer and performance.
doMethodLater adds your method to taskMgr with execution delay, and that’s it. Nothing more, nothing less.
Whether your method would continue or not, it depends on your method’s return value. If it returns Task.cont, then it would be executed again next frame.
Open your Task.py (in direct/src/task):
class Task:
# This enum is a copy of the one at the top-level.
exit = -1
done = 0
cont = 1
again = 2
# Check the return value from the task
if ret == cont:
# If this current task wants to continue,
# come back to it next frame
taskDoneStatus = cont
frameFinished = 1
elif ret == done:
# If this task is done, increment the index so that next frame
# we will start executing the next task on the list
self.index = self.index + 1
taskDoneStatus = cont
frameFinished = 0
elif ret == exit:
# If this task wants to exit, the sequence exits
taskDoneStatus = exit
frameFinished = 1
def __repeatDoMethod(self, task):
"""
Called when a task execute function returns Task.again because
it wants the task to execute again after the same or a modified
delay (set 'delayTime' on the task object to change the delay)
"""
this function just waits the time you set and after this continues your execution indefinitely(if return Task.cont)
What I want is: the function executes each 2 seconds, and not waits 2 seconds and executes indefinitely
any suggestion?
Well, C#er clearly said that the task must repeat every 2 secs WITHOUT the first delay.
About spawning the task again & again, you’re right (BTW the tasks list didn’t increase, but yes doMethodLater still has to do needless lines), so this works too :