PDA

View Full Version : timer question again


Elittdogg
10-18-2007, 09:23 AM
So I've created an "elapsed time" timer. Now I want that timer to start when I start my program (i.e. when I start moving the picture) (which starts on an "onkeydown" command).

def timer1():
print 'Elapsed time:',viz.elapsed(), 'seconds'
vizact.ontimer(60,timer1)
def onkeydown(key):
if key == ' ':
quad.add(MovingRoom)


So what happens now is once Vizard is done loading the stimulus timer1 starts automatically and even if I don't start moving the picture. So after 60 seconds it will print something like "Elapsed time: 60.0023467 seconds". What I need Vizard to do is to start that only once I've hit the spacebar ' ' key to start moving the picture. But I'm having a lot of trouble embedding it in there without having a whole other timer. What can I do?

farshizzo
10-18-2007, 09:46 AM
Just register the timer in your keyboard callback:def timer1():
print 'Elapsed time:',viz.elapsed(), 'seconds'

def onkeydown(key):
if key == ' ':
quad.add(MovingRoom)
vizact.ontimer(60,timer1)Also, in the future please use the tags when posting code snippets. It preserves the indentation, which is necessary for python scripts.

Elittdogg
10-18-2007, 10:20 AM
I tried exactly that. That was my first thought, but I got this error message:

Traceback (most recent call last):
File "<string>", line 2, in ?
File "MOVING ROOM (FINAL).py", line 61
vizact.ontimer(60,timer1)
^
SyntaxError: invalid syntax


So that's why I'm stuck

farshizzo
10-18-2007, 10:29 AM
That means the indentation on that block of code is inconsistent. Select the entire block of code in Vizard then press Alt-T to tabify the region. Vizard 3.0 will display squiggly lines on lines of code with inconsistent indentation. I would suggest upgrading if possible.