Game Development Community

playAudio Problem

by Lucas Goss · in Torque Game Engine · 06/07/2002 (4:57 pm) · 1 replies

I am trying to use the playAudio(...) function in the code (not script), to play a 3d sound. However I can only get it to work one way.

example of initial script and code.
Script:
datablock AudioProfile(MySound)
{...}

// later in script
datablock PlayerData(MyPlayer)
{...
   sound = MySound;
}

Code:
// in .h file
struct PlayerData: public ShapeBaseData {
...
enum Sounds {...
   aSound,
   ...};
}

// Then in .cc file
void PlayerData::initPersistFields()
{...
   addField("sound",TypeAudioProfilePtr,Offset(sound[aSound],PlayerData));
...
}

Ok, that's the setup, now here is the actual calls (some work, some don't).

SCRIPT:
// WORKS!
%obj.playAudio(0, MySound);

// DOESN'T WORK
%obj.playAudio(0, sound);

CODE:
// DOESN'T WORK
playAudio(0, mDataBlock->sound[PlayerData::aSound]);

// haven't tested this function but I think it works
alxPlay(mDataBlock->sound[PlayerData::aSound],&getTransform());

I have no idea why I don't get any sound out of the playAudio function. I know it enters the function, but I hear nothing. Any help is much appreciated.

#1
06/10/2002 (8:15 am)
Ok I've found where the sound is failing but I'm not too sure on how to fix it. The playAudio function calls a function updateAudioState, which is where the sound is not being played.
void ShapeBase::updateAudioState(Sound& st)
{
   if (st.sound) {
      alxStop(st.sound);
      st.sound = 0;
   }
   if (st.play && st.profile) {
      if (isGhost()) {
         if (Sim::findObject(SimObjectId(st.profile), st.profile))
            st.sound = alxPlay(st.profile, &getTransform());
	 else  // FUNCTION RESOLVES HERE!!!
            st.play = false;
      }
      else {
         // Non-looping sounds timeout on the server
         st.timeout = st.profile->mDescriptionObject->mDescription.mIsLooping? 0:
         Sim::getCurrentTime() + sAudioTimeout;
      }
   }
   else
      st.play = false;
}

The function ends up going to the else statement where it says FUNCTION RESOLVES HERE!!! So I don't know why it can't find the profile object. If I remove the if statement for find object the sound only plays once and then vanishes. Any suggestions?