Hiya,
Im trying to make a countdown timer for a racing game. Thanks to panda.egg for inspiring me
Right now the timer is working fine and I am trying to write a readRemainingTime() (see the code), but I’m having trouble accessing time of the task from this function. How do I do that?
Right now I get the following error:
Traceback (most recent call last):
File "timer.py", line 38, in ?
t = readRemainingTime( guiTimerTask )
File "timer.py", line 35, in readRemainingTime
return int( givenTime ) - int( task.time )
AttributeError: 'function' object has no attribute 'time'
I’m not very adept at coding python yet, but I have some java / general OO coding experience. Can somebody help me past this problem.
General suggestions are also welcome
Thanks
Code Follows:
import direct.directbase.DirectStart
from direct.gui.Directgui import *
from direct.task import Task
guiTimer = DirectLabel()
guiTimer.reparentTo(aspect2d)
guiTimer.setScale(0.1)
givenTime = 30
def dCharstr( theString ):
if len( theString ) != 2:
theString = '0' + theString
return theString
def guiTimerTask( task ):
remainingSeconds = int( givenTime ) - int( task.time )
remainingMinutes = int( remainingSeconds / 60 )
remainingHours = int( remainingMinutes / 60 )
if remainingSeconds >= 0:
guiTimer['text'] = 'Remaining Time ' + str( dCharstr( str( remainingHours ) ) ) + ':' + str( dCharstr( str( remainingMinutes % 60 ) ) ) + ':' + str( dCharstr( str (remainingSeconds % 60) ) )
else:
guiTimer['text'] = 'Remaining Time 00:00:00'
return Task.cont
def increaseGivenTime( seconds ):
givenTime = givenTime + seconds
def reduceGivenTime( seconds ):
givenTime = givenTime - seconds
def readRemainingTime( task ):
return int( givenTime ) - int( task.time )
taskMgr.add( guiTimerTask, 'guiTimerTask' )
t = readRemainingTime( guiTimerTask)
print t
run()