WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   audio object string (https://forum.worldviz.com/showthread.php?t=1395)

Jerry 03-13-2008 10:01 AM

audio object string
 
The following script contains a function which attempts to play
an audio file which is passed as
an argument. Before calling the function I want to construct the
name of the audio object by concatenating character strings, but
it doesn't work. Can you tell me the correct way to do this?

Code:

from viz import *

go()

sound1 = add('boing!.wav')

def playit(snd):
        snd.play()

num = 1
s = 'sound'+str(num)

playit(s)


farshizzo 03-13-2008 11:06 AM

Are you trying to look up a Python object by its name? The following will look up the name in the current global variable scope and play the sound if it exists:
Code:

def playit(snd):
        soundObject = globals().get(snd,None)
        if soundObject is not None:
                soundObject.play()



All times are GMT -7. The time now is 12:04 AM.

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