Task time

Whenever I run my task code it says. “World instance had no attribute ‘time’”.
My code is…

import direct.directbase.DirectStart
from direct.task import Task
from direct.showbase.DirectObject import DirectObject
import time, math, sys, os

class world (DirectObject):

	def __init__(self):
		
		self.acceptOnce('a',self.taskOnTime,extraArgs=['hi'])
		
	def taskOnTime(task, self):
		
		if task.time < 2.0:
			return task.cont
		extra = OnscreenText(text="Game will begin in 5 seconds...",
			style=1, fg=(1,1,1,1),
			pos=(-.70,-.6), scale = .1)
		return task.done

w = world()

run()

Thank you for all the help. :slight_smile:

Uhm, this looks suspicious:

[code]
def taskOnTime(task, self): [/code
Change that to:

[code]
def taskOnTime(self, task): [/code

‘self’ should usually be the first argument.

I made it that but now it says ‘str’ object has no attribute ‘time’.

Actually, that’s because the argument passed in ‘task’ is in fact a string, which contains ‘hi’. That function is not a task, in fact, while you treat it like one.

so what do I do to make it work then :bulb:

the manual is your friend:

http://panda3d.org/manual/index.php/Tasks

oh lol… Thank you guys for helping me. :smiley: