time

Hey guys,

I want to check if a something is constant for 3 seconds (a variable), and then perform a task.

Never worked before with time, any ideas how I can go about doing it?

Thanks!

import direct.directbase.DirectStart
from direct.task import Task
import random

class World():
    def __init__(self):                
        self.variable=1
        self.prev=1
        self.value=[1,'a',[1,1,1],('a','f'),self]            
        self.tick=1
                
        taskMgr.doMethodLater(self.tick,self.check,'check')
        
    def check(self,task):
        #create a random number from 0-4
        nr=int(random.random()*4.9)
        
        #save prev variable
        self.prev=self.variable        
        
        #set new variable
        self.variable=self.value[nr]
        
        print self.tick,'seconds passed'        
        if self.variable==self.prev:
            print 'variable did not change'
            print 'Will not perform a task\n'
        else:
            print 'variable did change'                    
            print 'was:',self.prev
            print 'is:',self.variable
            self.ataskthatisindeed()
            
        return task.again 
    def ataskthatisindeed(self):
        print 'Now i will perform a task','\n'
        
w=World()

run()

Thanks dude!

Works!

No problem Dude!

Hey Dude! Where’ my Panda ?
Hum…! Sorry… couldn’t resist!
:blush: