Reference: Flow control

Director basics

The director command allows you to execute a function that includes interruptions without halting rendering of the world or the execution of other code within your script. The function is run as a parallel thread to the rest of the script's activity. If you quit the world before this function is executed, Vizard will force them to quit and warn you that it did so. Director functions are handy if you have a thread of code that halts (e.g. because of a time delay,  a "while:", etc.), but you don't want to halt the rendering of the world or the execution of other code.

 

Note:  The Director command creates an asynchronous thread and can cause unexpected results if not used correctly. In almost all cases, tasks should be used instead.

 

 

#Add a spinning model and some text.
wheelbarrow = viz.add('wheelbarrow.ive')
wheelbarrow.setPosition(0,1.8,3)
wheelbarrow.addAction( vizact.spin(0,1,0,60) )
text = viz.addText( '', viz.SCREEN)
text.setPosition(.5,.3 )

#Define a function that includes director pauses.
def changeText():
    #Wait 30 frames.
    viz.waitframe(30)
    text.message( 'getting' )
    #Wait 2 seconds.
    viz.waittime(2)
    text.message( 'dizzy' )
    #Wait for the arrow down key to be pressed.
    viz.waitkeypress(viz.KEY_DOWN)
    text.message(' ')

#Use director to call the function so that it
#won't stop the rendering of the world.
viz.director( changeText )

 

See also

In this section:

Director command table

Other sections:

Action basics

Tasks basics