WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Thread Tools Rate Thread Display Modes
Old 05-31-2007, 07:40 AM
djdesmangles djdesmangles is offline
Join Date: Nov 2006
Posts: 88
Exclamation Some problems...

Hello Wizards,

I've some codes that doesn't work... If I want a delay of 2 seconds before playing a sound:

# my variables
# wait for 2 seconds before playing track
def onTimer(num):
viz.callback(viz.TIMER_EVENT, onTimer)
viz.starttimer(0, 2)

- If I want to listening to my joystick event:

# add a joystick and listen
joy = vizjoy.add()
def joystickListener(num):

y = joy.getPosition[1]
x = joy.getPosition[0]
if math.fabs(y) > 0.2:
if math.fabs(x) > 0.2:
viz.callback(viz.TIMER_EVENT, joystickListener)
viz.starttimer(1, 0.001, viz.FOREVER)

The problem is that only the joystick fonction will work. The sound will never be played. If I change the first fonction to something that requires an infinite loop, the two callbacks will work !!!

I don't undestand why I can't have a delay while starting my joystick...

Reply With Quote
Old 05-31-2007, 11:08 AM
farshizzo farshizzo is offline
WorldViz Team Member
Join Date: Mar 2003
Posts: 2,849

You can only register one global callback function per event. If you want multiple callback functions for an event you need to use event classes. In this example you can also use a different timer ID for each case:
def onTimer(num):
    if num == 1:
        #Perform joystick listener code
    elif num == 0:
viz.callback(viz.TIMER_EVENT, onTimer)
viz.starttimer(1, 0, viz.FOREVER)
viz.starttimer(0, 2)
Alternatively, you could use the vizact library:
def joystickListener():
    #joystick listener code
vizact.ontimer(0,joystickListener) #Call function every frame

vizact.ontimer2(2,0, #Play track in 2 seconds
Reply With Quote
Old 05-31-2007, 11:27 AM
djdesmangles djdesmangles is offline
Join Date: Nov 2006
Posts: 88
Thumbs up Oki...

OOoooooww... I'm going to try...

Thanks a lot...
Reply With Quote

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 11:13 PM.

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