Vizard 7 » Tutorials & Examples » Getting your feet wet » Timer Events
7.7

Tutorial: Timer Events

Next, we're going to add a timer event. Be sure you have the script you completed in the previous section because this is where we will begin.

 

Timer events are an extremely useful building block because they let you add time as an integral aspect to your 3D worlds. Timers can be used to schedule other events, trigger a carefully choreographed sequence, and to implement custom animations. Below, we're going to use it to start the plants spinning at different times:

 

Replace:

for plant in plants:
    plant.addAction(spin)

With:

def spinPlant(plant):
    plant.addAction(spin)
vizact.ontimer2(0.5,19,spinPlant,vizact.choice(plants))

Run the script and one by one the plants will start spinning. There are four arguments passed to the vizact.ontimer2 command:

 

Time interval - 0.5 seconds: How often the timer will expire.

Repeats - 19: How many times to repeat the timer after the first timer expires.

Function - spinPlant: The function to call when the timer expires.

Function Argument - vizact.choice(plants): Argument to pass to the function. In this case, the argument is a plant from the plants list.

 

The function spinPlant will get called every 0.5 seconds for a total of 20 times (1 + 19 repeats). Each time, the spin action is applied to the next plant in the list.

 

For this example we wanted a timer with a fixed number of repeats. It's also quite common to use timers that repeat indefinitely. The vizact.ontimer command serves that purpose. It's just like ontimer2 without the repeats argument.

Launch into a new world

Creating a new Script

Setting the Scene

Moving the Viewpoint

Manipulating 3D Models

Animating 3D Models

Timer Events

Adding Avatars

Inserting User Interaction