WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Timer Question (https://forum.worldviz.com/showthread.php?t=1930)

durf 03-24-2009 09:18 AM

Timer Question
 
Hello,

I have a program that I want to run for 10 minutes. In those 10 minutes I want it to check for the time. For the first 3 minutes I want it to run one function. After the 3 minutes expires I want it to start another function for 4 minutes. When that expires I want it to run another function for the remaining 3 minutes.

Do I use a starttimer and have the starttimer equal something and put the 3 functions in a loop so it keeps checking the time?

Im looking for a good way to write this.

Thanks

Example:

viz.go()
.
.
.
def function1():

"code"

//end of function 1

def function2():

"code"

//end of function 2

def function3():

"code"

//end of function 3

farshizzo 03-24-2009 09:57 AM

Here is an example that uses the viztask module to control the timing of the 3 different functions:
Code:

import viz
import vizact
import viztask
viz.go()

def func1():
        pass
       
def func2():
        pass
       
def func3():
        pass

def MainTask():
       
        #Run func1 for 3 minutes
        timer = vizact.ontimer(0,func1)
        yield viztask.waitTime(180)
        timer.remove()
       
        #Run func2 for 4 minutes
        timer = vizact.ontimer(0,func2)
        yield viztask.waitTime(240)
        timer.remove()
       
        #Run func3 for 3 minutes
        timer = vizact.ontimer(0,func3)
        yield viztask.waitTime(180)
        timer.remove()
       
        #Quit script
        viz.quit()
       
viztask.schedule( MainTask() )


durf 03-31-2009 09:18 AM

Ok thanks for that... If I wanted to do it via pressing keys and not a timer how would I do that. I got it to work but I have trouble after I go on to the next function... I can never go backwards.

IE

I press 'a' to initiate def func1():

I then press 's' to iniatiate def func2():

If I press 'a' again I get an error. I assume I need a ontimer or something but I have trouble trying to figure that out.

Any insight would be much appreciated

Jeff 03-31-2009 05:29 PM

If you just want to call functions based on keypresses use something like

Code:

vizact.onkeydown('a', func1)
vizact.onkeydown('s', func2)



All times are GMT -7. The time now is 04:01 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC