Hi everybody, long time!
So I’ve been trying to use Audaspace in UPBGE 0.3 but I’ve run into some complicated problems with - I believe, relative file pathing. I briefly got it to work by using an explicit path “C:\Users\Projects\etc”, but ofcourse I’d like this game to work regardless of where it’s installed on one’s harddrive, so I’ve tried to use relative paths. However, even though when debug-printing the paths, the relative path generated with ‘bge.logic.expandPath(’\‘)’ is identical to the explicit path, but UPBGE returns an error to the tune of ‘Object not of type Sound!’.
I’ve tried forcing a pathing error by deliberately pathing to a file that doesn’t exist, and the exact same error is returned: “Object no of type Sound!”. It couldn’t be finding an object, so it makes me think the string argument is being recognised as an Object for some reason. Has anyone run into this problem before? Or atleast, does anyone know what’s going on?
This is a class I created to handle instancing sounds in other scripts:
import bge
import aud
class soundObject():
def playSound(fileName, volume, pitch):
device = aud.Device()
handle = device.play(fileName) # <--- This is the line the error claims is calling an "Object not of type Sound!"
handle.pitch = pitch
handle.volume = volume
def classDebug(callBool, pathsBool, fileName):
rootPath = bge.logic.expandPath("//")
soundPath = rootPath[:len(rootPath) - 8] + "\\sounds"
sound = soundPath + fileName
if callBool:
print ("Class SoundObject called")
print ("Module classDebug called")
if pathsBool:
print ("Root path: " + rootPath)
print ("Sound path (folder): " + soundPath)
print ("Sound path (file): " + sound)
print ("Ref. path (file): " + "C:\\Users\\Thomas\\Documents\\Projects\\Games\\Doom-Like\\sounds\\Gun_Small_Fire.ogg")
And this is an excerpt of the script that is calling the function, and it is this call that generates the error:
if bge.logic.KX_INPUT_JUST_ACTIVATED in bge.logic.mouse.inputs[bge.events.LEFTMOUSE].queue:
if cameraOb["shootReFire"] > reFireRate[self.equipped]:
cameraOb["shootReFire"] = 0.0
self.weapons[self.equipped][1] -= 1
self.animLoop = True
if self.equipped == 0:
sounds.soundObject.playSound("C:\\Users\Thomas\Documents\Projects\Games\Doom-Like\sounds\Gun_Small_Fire.ogg", 0.5, 1.0) # <--- This is the line that calls the function of the sound class that is causing the error
Verbatim error:
[ERROR] KX_PythonComponent[weaponOperations] - Failed to invoke the update callback.
Traceback (most recent call last):
File "C:\Users\Thomas\Documents\Projects\Games\Doom-Like\blends\Level_1.blend\Player_Controller.py", line 204, in update
File "C:\Users\Thomas\Documents\Projects\Games\Doom-Like\blends\Level_1.blend\sounds.py", line 9, in playSound
TypeError: Object is not of type Sound!