Game Development Community

alxStop Not Working [SOLVED]

by Andrew H · in Torque Game Builder · 11/06/2011 (7:07 pm) · 7 replies

I've been trying to create a system to start and stop music. Here's the code for my stop function:
function stopSong(%music)
{
   alxStop(%music);
}

The problem here is that it does NOTHING. I call stopSong(mainMenuMusic), etc. and nothing happens. It keeps playing. What am I dong wrong here?

#1
11/06/2011 (7:16 pm)
Can you use alxStopAll() instead? I've also had trouble with alxStop, so I switched to that.
#2
11/07/2011 (12:13 am)
Try to pass in sound handle you getting from alxPlay() instead of track name.

TGB's sound system is built on OpenAL, hence al* and alx* names, lack of documentation (there is plenty for OpenAL itself though) and things are done in a little different way there.
#3
11/08/2011 (5:53 pm)
I tried that as well - doing $musicHandle = alxPlay(mainMenuMusic) and then alxStop($musicHandle). No dice.

Also, I could use alxStopAll() but I'll eventually come to a situation where I cannot use it - where the best solution would be knowing how to use alxStop().
#4
11/10/2011 (12:35 pm)
Hello? Little help here!
#5
11/11/2011 (5:36 am)
Please? I could use some help!
#6
11/11/2011 (7:38 am)
Hi Laura, I hope this hasn't been causing you too much trouble. I did some testing and found this to work fine in TGB 1.7.5:
function testObject::onLevelLoaded(%this, %scenegraph)
{
   $SOUND = 1;
   
   echo("loading audio datablocks");   
   new AudioDescription(MusicLooping)
   {
      volume = 1.0;
      isLooping= true;
      is3D = false;
      type = $MusicAudioType;
   };
   
   playMusic("test", 1); 
}

function getAudio(%name, %type)
{
   echo("setup audio objects");  
   if (isObject(%name))
      return;
   
   new AudioProfile(%name)
   {
      filename = "~/data/audio/" @ %name @ ".wav";
      description = %type;
      preload = false;
   };
}

function playMusic(%sound, %volume)
{
   echo("play music");  
   
   // get profile for sound effect
   getAudio(%sound, "MusicLooping");    
   
   if($SOUND)
   {
      // play sound
      MusicLooping.volume = %volume;
      $bgm = alxPlay(%sound);
   }
   
   schedule(5000, 0, "stopMusic");
}

function stopMusic()
{
     alxStop($bgm);
}
Note: testObject was just a sceneObject I dragged out into the editor to kick off the code
Can you test and if it works, compare what you're doing? I did see some oddness in the source that made me think it wouldn't work where my $bgm was a negative number and the alxStop usage states:
Quote:
The ID (a non-negative integer) corresponding to a previously set up sound source."
#7
11/11/2011 (4:17 pm)
That worked! Thanks, Patrick!