BGE 2.56a/Python - Play/Change sounds in game

I was working on transferring some old logic brick based games of mine to python and I came across a load of sound actuators that needed to be dealt with.

It isn’t exactly convenient to have 10 sound actuators linked all over the place, so I wanted to either compress them into 1 actuator that would swap sound files in game or find a way to play them in the python script using the current modules included in Blender.

I couldn’t find any python command to do it, so I tried the first idea of 1 sound actuator, but I am unable to get python to assign a new sound file to the actuator:

AttributeError: ‘KX_SoundActuator’ object has no attribute ‘fileName’

Any ideas on what to do?

try


print ("attributes of %s: %s" % (yourActuator.name, str(dir(yourActuator)) )

I’ve tried that and found the attributes of the sound actuator (quite a useful trick, thanks):

https://lh5.googleusercontent.com/_DFvJNtBvuLM/TXfU-jh7ToI/AAAAAAAAAO8/sk1C-KVJFGs/sound%20dir.png

I see no attribute for the sound file though. One odd thing I did notice though, is that when I mouse over the different options of the sound actuator (which normally show the python tool tips) all of them showed “SoundActuator.attribute” except the line where the filename of the sound goes. Instead of “SoundActuator”, it was just “Sound.name”, and looked like it didn’t belong to the sound actuator.

Is there any alternative to just play a sound file saved in the .blend? Perhaps without using an actuator?