Py: Audaspace,get sound from actual path.

How would i make audaspace get a file that is located in the same location as the .blend file.
I have .blend in a folder,and in the same folder i have another folder with sounds into. I dont want to define the full location as I want to make it work no matter where is.

sh1_fire = aud.Factory(’//Weapons\sh1_fire.wav’)
handle =

What am I doing wrong?


Use logic.expandPath() to expand the path out to where you need it to be. If you give ‘//’ as the first part of the string, it will be relative to the blend file, so:

 sh1_fire = aud.Factory(logic.expandPath('//Weapons/sh1_fire.wav'))
 handle =

As a side-note, I believe forward slash characters in strings are escape characters (i.e. ‘\r’ is a return character, while ‘/r’ isn’t). So pay attention that you keep it consistent and use whichever one (forward or back) that works. I believe forward slashes work.

If you define all of your sounds in a single place, then you can optimize things by defining the resource folder and loading the sounds before-hand to make it more readable:

# Earlier in your code

respath = logic.expandPath('//Weapons/')

logic.sounds = {
'sh1_fire' : aud.Factory(respath + 'sh1_fire.wav').buffer()     # Good to buffer sounds that are short and get played a lot

# And then, when you want to play...

handle =['sh1_fire'])

Thank you SolarLune, works just great!