View Full Version : timer counter
Wenamun
06-13-2007, 08:12 AM
Is it possible to count how many times a timer has been called back (without the use of a counting variable)?
viz.elapsed() gives me the same numbers every time because it's only counting how long THIS instance has run. what about all instances?
thanks!
Wenamun
06-13-2007, 08:54 AM
i guess this is a better question:
i want to draw a line between the coordinates an object was at two seconds ago and the coordinates the object is at now. so i ran a timer to repeat every 2 seconds. the problem is obvious, and i would imagine the solution is equally so. i just can't figure it out.
the first time the function runs, i am told the variable 'oldLoc' is not defined. but if i define it in the first line of the function, it will be initialized every time the function is run and it will always be '[0,0,0]'. how can i work around this? i figure i could run a counter that assigns an arbitrary coordinate to 'oldLoc' the first time the function is run. but no matter how i do it, that counter is reset (initialized) every time the function is invoked.
hope this makes sense. thanks!
def mytimer(num):
newLocs = []
for x in range(numLights):
newLoc = balls[x].get(viz.POSITION)
newLocs.append(newLoc)
viz.startlayer(viz.LINES)
viz.vertexcolor(1,0,1)
viz.linewidth(1)
#print 'newLocs[',x,']',newLocs[x]
viz.vertex(newLoc)
viz.vertex(0,0,0)
tail = viz.endlayer()
tails.append(tail)
tail.size(0,0,0,1,viz.TIME)
oldLocs = newLocs
farshizzo
06-13-2007, 02:35 PM
You need to declare the oldLocs variable as global. Your code should look like the following:oldLocs = [ [0,0,0] for x in range(numLights) ] #Initialize to some value
def mytimer(num):
global oldLocs
newLocs = []
for x in range(numLights):
newLoc = balls[x].get(viz.POSITION)
newLocs.append(newLoc)
viz.startlayer(viz.LINES)
viz.vertexcolor(1,0,1)
viz.linewidth(1)
#print 'newLocs[',x,']',newLocs[x]
viz.vertex(newLoc)
viz.vertex(0,0,0)
tail = viz.endlayer()
tails.append(tail)
tail.size(0,0,0,1,viz.TIME)
oldLocs = newLocs
vBulletin® v3.8.7, Copyright ©2000-2024, vBulletin Solutions, Inc.