PDA

View Full Version : reseting actions


nlfrnassimi
03-19-2009, 12:34 AM
Hi, I have created a test code. In my code there is a ball that waits 5 seconds before it changes color, and according to the color changing there are balls moving around. after the actions have taken place, I want to reset them so that everything starts from the beginning. How can I do that?

Here is my code:

import viz

viz.go()

import viztask

viz.clearcolor( viz.SKYBLUE )
viz.add( 'tut_ground.wrl' )
ball1 = viz.add( 'white_ball.wrl' )
ball1.setPosition( 0, 3, 4 )

ball2 = viz.add('soccerball.ive')
ball2.setPosition(2,0.3,6)

ball3 = viz.add('soccerball.ive')
ball3.setPosition(-2,0.3,4)




def changeColor():
while True:


color = ball1.color(viz.RED)
moveball2()

yield viztask.waitTime( 5 )


color = ball1.color(viz.YELLOW)
moveball3()

yield viztask.waitTime(5)


color = ball1.color(viz.GREEN)
rotateball3()
safe()

yield viztask.waitTime( 5 )
stopRotate()



viztask.schedule( changeColor() )

def moveball2 ():
ball2.addAction( vizact.goto ([-1,2,6] ) )



def moveball3 ():
ball3.addAction( vizact.goto ([2,2,6] ) )

def rotateball3 ():
ball3.addAction( vizact.spin([0,1,0],90,viz.FOREVER,100))

def stopRotate ():
ball3.endAction()

def safe() :
safe = viz.addText('SAFE', viz.WORLD)
safe.setPosition(-1,2,5)
safe.scale(.5,.5)