View Single Post
  #2  
Old 06-04-2010, 12:50 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,448
The viztask.waitButtonDown command waits for a GUI button object to be pressed. To wait for a joystick button press in your task function you can create a custom condition. The task function in the following example waits for either buttons 1 or 2 to be pressed before it continues:
Code:
import viz
import viztask
import vizjoy

viz.go()
joystick = vizjoy.add()

def buttonTask():
	
	d = viz.Data()
	waitButton1 = waitJoyButtonDown(joystick,1)
	waitButton2 = waitJoyButtonDown(joystick,2)
	
	yield viztask.waitAny([waitButton1,waitButton2],d)
	
	if d.condition is waitButton1:
		print 'button 1 was pressed'
	else:
		print 'button 2 was pressed'
		
	viz.quit()	

class waitJoyButtonDown( viztask.Condition ):
    def __init__( self, joy, button ):
        self._joy = joy
        self._button = button
   
    def update( self ):
        return self._joy.isButtonDown(self._button)

viztask.schedule( buttonTask() )
Reply With Quote