View Single Post
  #4  
Old 01-29-2007, 11:01 AM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
Ah, the "global" varable problem. The first sound file you create and assign to the "music" varable is a global varable.

When you use the equals sign in a fuction, it creates a *new and local* varable which only lives within the function. So your "Change" fuctions are trying to create new sound objects and playing them without reasigning the global music function. You are probably getting the "accessing varable before instatiated" error here because you are trying to rewind() the music varable, then assigning to it.

The following code avoids this by added a 'currentMusic' parameter to the fuctions which takes as an argument the global music varable:

Code:
music = viz.add('song.mp3')
music.play()

def stopOldAndPlayNewSong(currentMusic, newSongFile):
    currentMusic.stop()
    currentMusic = viz.add(newSongFile)
    currentMusic.play()

def onkey(key):
    key == '1':
         stopOldAndPlayNewSong(music, 'song1.mp3')
Also, Vizard does not have a rewind() function.


Rather than diving right into Vizard programming, I strongly suggest investing in your python skills. Here is an exclent tutorial: http://docs.python.org/tut/
__________________
Paul Elliott
WorldViz LLC
Reply With Quote