Game Development Community

Need Help with no sound when key is pressed**FIXED**

by Donnie Hutson Jr · in Torque Game Engine · 01/25/2012 (5:59 pm) · 3 replies

Ok heres what I have!! I'm trying to play a on/off sound when I press my "n" key to activate my nightvision. The nightvision works great and even reports in hud when activated and deactivated, only no sound will play and I tried my best to try everything I can before posting for help, so any would be great!!

ok here's my code in client/default.bind.cs
$NightVisionVar = "1";
function toggleNightvision(%val)
{
   if (%val)
   {
      if($NightvisionVar)
      {
         $NightvisionVar = "0";
         commandToServer('EnableNightvision');
         commandToServer('NightvisionSoundon');
      }
      else
      {
         $NightvisionVar = "1";
         commandToServer('DisableNightvision');
         commandToServer('NightvisionSoundoff');
      }
   }
}

moveMap.bind(keyboard, "n", toggleNightvision);

and this is what I have in my server/commands.cs file
//at the top of commands.cs
$SimAudioType = 2;
 
singleton SFXDescription(nightvision3d)
{
   volume            = 1.0;
   isLooping         = false;
   loopCount         = 0;
   is3D              = true;
   ReferenceDistance = 10.0;
   MaxDistance       = 100.0;
   type              = $SimAudioType;
};

datablock SFXProfile(nightvisionsndon)
{
   filename    = "art/sound/NightVision/mono_nightvision_on.wav";
   description = nightvision3d;
   preload     = true;
};

datablock SFXProfile(nightvisionsndoff)
{
   filename    = "art/sound/NightVision/mono_nightvision_off.wav";
   description = nightvision3d;
   preload     = true;
};

//at the bottom of commands.cs
//------------------------------------------------------------------------------
// Nightvision Controls
//------------------------------------------------------------------------------ 

function serverCmdEnableNightvision(%client)
{
   %player = %client.player;
   %player.NightvisionEnable();
      
   messageClient(%client, '', "NightVision Activated!!");   
}

function serverCmdDisableNightvision(%client)
{
   %player = %client.player;
   %player.NightvisionDisable();
   
   messageClient(%client, '', "NightVision Deactivated!!");   
}

//------------------------------------------------------------------------------
// Nightvision Audio Controls
//------------------------------------------------------------------------------ 

function serverCmdNightvisionSoundon(%client)
{
   // Create and play a source from a pre-existing profile:
   %transform = %client.player.getTransform;
   ServerPlay3D(nightvisionsndon, %transform);
  
   echo("playsound NightVision ON!!! ");    
}

function serverCmdNightvisionSoundoff(%client)
{
   // Create and play a source from a pre-existing profile:
   %transform = %client.player.getTransform;
   ServerPlay3D(nightvisionsndoff, %transform);
            
   echo("playsound NightVision OFF!!! ");   
}

Also note, my audio files are mono!! Thanks in advance for any help!!

About the author

Electrical Engineer by trade, Computer geek by night. Still learning and loving every minute.


#1
01/27/2012 (1:42 am)
have tried using alxPlay() instead? Create an audioProfile instead and try using alxPlay(profile_name).
#2
01/27/2012 (10:16 am)
Which engine? You're posting in the TGE forums, and SFX datablocks are for TGEa or T3D. TGE uses 'AudioProfile' and 'AudioDescription'.


Also, since you are calling a function and not a property, your call to getTransform should read:
%transform = %client.player.getTransform();
#3
01/28/2012 (11:44 am)
Michael, you were right....I also had to list my audio description and profiles in my datablocks/audioprofiles.cs instead of commands.cs...Works great and thank you very much.....