WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-14-2008, 10:10 AM
JPWann JPWann is offline
Member
 
Join Date: Aug 2007
Posts: 2
Question Repeating timer_callbacks in for_loops

This is a beginners Q, as I have clearly missed something about how timers can be embedded in loops:

I have a function with a timer-callback so I can do frame-by-frame manipulations to a ball in flight. I can run repetitions of this ball-flight using a second timer as below:

def ballfunc(a,b,c,d,e):
. StartT = viz.tick()
. def balltimer(timernum):
. ball.setScale....etc...
.
. viz.callback(viz.TIMER_EVENT,balltimer)
. viz.starttimer(1,0.02,48)
vizact.ontimer2(2,10,ballfunc,0,0,-1,1,0.5)

But what I actually want is to nest ballfunc in a for_loop so I can pass it different parameters for each repetition. But my clumsy attempts to do this don't work (see below). How do I run, say 10 reps of ballfunc with different parameters passed to it each time ?:

def BallFlight():
. for i in range(0,9):
.. ball.setPosition(ball.initial)
.. yield viztask.runAction(ball,ballfunc(0,0,-1,1,SCALESEQ[i]))
.. yield viztask.waitTime(2)
viztask.schedule( BallFlight() )

Last edited by JPWann; 01-14-2008 at 10:12 AM.
Reply With Quote
  #2  
Old 01-14-2008, 11:01 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Just call the function in each iteration of the loop in your BallFlight task:
Code:
def BallFlight():
	for i in range(0,9):
		ball.setPosition(ball.initial)
		ballfunc(0,0,-1,1,SCALESEQ[i])
		yield viztask.waitTime(2)
viztask.schedule( BallFlight() )
Reply With Quote
  #3  
Old 01-15-2008, 02:55 AM
JPWann JPWann is offline
Member
 
Join Date: Aug 2007
Posts: 2
Smile Thanks

Thanks Frashizzo,

I thought I'd tried all the combinations of my version - but see my error now - excellent support !
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:43 PM.


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