PDA

View Full Version : exiting a yield statement


starbug
01-12-2010, 12:58 PM
Hello there,

I have a question regarding exiting a yield statement, after a certain time elapsed. I am changing a global variable according to a keypress (using yield viztask.waitKeyDown) within a function, if that keypress should not happen, I want to exit the yield statement after a certain time interval. And continue the protocol with the unchanged global variable.
I might be wrong using yield, and there is some other way (I read about python threading?Running a timer parallel to yield?), could you point me to some example code? I couldn't find this scenario in the tutorial.
Thank you.




Step=1
Motion = 15
def control():
global Motion
..... #dosomething with Motion
for i in range(1,x)
d = viz.Data()
yield viztask.waitKeyDown(['y','n'],d) #or, if no key was pressed, after 2 sec exit yield
if d.key == 'y':
Motion = Motion - Step
elif d.key == 'n':
Motion = Motion + Step

farshizzo
01-12-2010, 02:19 PM
Have a look at the viztask.waitAny (http://www.worldviz.com/vizhelp/commands/viztask/waitAny.htm) condition. I believe the example on that page does exactly what you want.

starbug
01-12-2010, 03:16 PM
Thank you! that I must have overlooked!