WorldViz User Forum

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

JMOwens 12-07-2007 07:06 AM

Timer cycling correctly?
 
Hi all,
I have a timer running my program at 1/60 second, as indicated below:

def masterLoop(num):
.
[main program here]
.
viz.callback(viz.TIMER_EVENT,masterLoop)
viz.starttimer(0,1/60,viz.FOREVER)

However, when I insert a viz.elapsed() into the callback, it returns values of roughly 0.004. I may be misunderstanding the function, but shouldn't it be returning 0.017, which is 1/60? Sorry if this is a dumb question, but it's really important that this timer is cycling correctly. Thanks for your help!

farshizzo 12-07-2007 09:35 AM

In Python, the result of dividing two integers will be another integer. Try the following in the interactive interpreter:
Code:

>>> 1/60
0
>>> 1/60.0
0.016666666666666666
>>> 1.0/60
0.016666666666666666

So your code is setting a timer to expire every 0 seconds, which will be every frame. You will need to do the following instead:
Code:

viz.starttimer(0,1/60.0,viz.FOREVER)

JMOwens 12-07-2007 09:57 AM

Oh man, thanks a lot - I knew that, but forgot it in the context of a fraction! Doh. Thanks again.


All times are GMT -7. The time now is 04:13 PM.

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