Game Development Community

Player Sounds

by Joshua Dixon · in Torque Game Engine · 11/22/2005 (9:39 am) · 3 replies

I have looked everywhere and most resources or threads I have looked at do not have the answer for this.

I have made some upgrades to the source code of Torque and I'm having some trouble.

I've added the JetPack resource to the engine and I'd like to play a sound when a player is in this state.

I've looked over the code for JetSound under FlyingVehicles and imported it into player.cc.

My compile goes off fine no errors or warnings. But when I start the game, press start mission then launch mission, it crashes.

This is what I've got and keep in mind I'm a hobbyist not a pro =P

player.h

struct PlayerData: public ShapeBaseData {
 enum Sounds {
 JetpackSound
 }
}

class Player: public ShapeBase
{
   AUDIOHANDLE mJetpackSound;
}
next is player.cc
player.cc

void PlayerData::initPersistFields()
{
   Parent::initPersistFields();
   addField("JettingSound", TypeAudioProfilePtr, Offset(sound[JetpackSound], PlayerData));
}

//----------------------------------------------------------------------------

IMPLEMENT_CO_NETOBJECT_V1(Player);
F32 Player::mGravity = -20;


//----------------------------------------------------------------------------

Player::Player()
{
   mJetpackSound = 0;
}
Player::~Player()
{
   if (mJetpackSound)
      alxStop(mJetpackSound);
}
void Player::updateMove(const Move* move)
{
//==================================================
	// Jetting
	//==================================================
	if (move->trigger[1] && !isMounted()) {   
		if (!mJetting && mEnergy  >= mDataBlock->minJumpEnergy)   {      
			mJetting = true;  
			
		}
		if (mJetting)   {      
			F32 newEnergy = mEnergy - mDataBlock->minJumpEnergy;     
			if (newEnergy < 0)      {   
			if (!mDataBlock->sound[PlayerData::JetpackSound])
				  return;
			   if (!mJetting) {
				  if (mJetpackSound) {
					 alxStop(mJetpackSound);
					 mJetpackSound = 0;
				  }
			   }
			   else {
				  if (!mJetpackSound)
					 mJetpackSound = alxPlay(mDataBlock->sound[PlayerData::JetpackSound], &getTransform());

				  alxSourceMatrixF(mJetpackSound, &getTransform());
			   }
				newEnergy = 0;  
				mJetpackSound = 0;       
				mJetting = false;      
				}      mEnergy = newEnergy;   
		}
	} else {   
		mJetting = false;
	}
	if (mJetting) {  
		acc.z += (mDataBlock->jumpForce / mMass) * 5 * TickSec;
	}

When I remove the line from init persist it doesn't crash after loading a mission.

I may be going about this entirely wrong, anyone help?

#1
11/22/2005 (10:03 am)
Where is sounds[] defined? You're probably giving the scripting language a pointer to data that doesn't exist, or that is used for something else. (ie, sound might be a 4 element array and you're giving it element #5.)
#2
11/22/2005 (3:50 pm)
I've gotten it to stop crashing.

Now It just wont play the sound.
#3
11/22/2005 (4:08 pm)
Thanks Ben, your post sent me in the right direction for the crashes, and after a little double checking to make sure everything was in the right place, my compile was done, deleted all the DSOs, fire it up and I've got my sounds =P

Thanks bunches

Edit:Typo