Game Development Community

AudioMood, and immediacy

by Azaezel · in Torque 3D Professional · 04/28/2014 (12:31 am) · 0 replies

Ok, so. 'Nother one from the trenches:

Spent the lions share of the night attempting to wrench in a variant of

www.garagegames.com/community/forums/viewthread/106725/1#comment-704147

using the following (general) logic:
function clientCmdUpdateEnergy(%rate,%val)
{//...
	
	if (%rate<50) AudioMoodAggressive.activate();
	else if (%rate<75)AudioMoodNeutral.activate();
	else AudioMoodCalm.activate();
//addotherstuff I'll repost later in a working format
}
While that worked to a degree, it did run afoul of our musician's request to be able to suppress one track and play another when using transitionOut = "Wait", since that forces the track to play right until the end, while transitionOut = "None" somehow caused all the tracks to attempt to play simultaneously.

Since I already had this other half scripted anyway, ended up reverting to it, and figured would post for comparison if someone more up on the present sfxPlaylist code wan't to see about reviewing that:

function clientCmdsetSong(%songPrefix)
{
	$songPrefix = %songPrefix;
   $prevSongSuffix = -1;
}

function clientCmdsetSongPosition(%songPos)
{
	if(!isObject($SongPositionList))  
    {  
        $SongPositionList = new arrayobject();
    }
	$songPositionList.Add(%songPos);
	$songPositionList.uniqueKey();
}

function clientCmdclearSongPositions()
{
	clearSongPositions();
}

function clearSongPositions()
{
	if(isObject($SongPositionList))  
		$SongPositionList.empty();
}

(Note half of that is likely irrelevant unless you're sticking level music in-game in an immersive manner but I'm feelin too lazy to rip that out tonight.)

function clientCmdUpdateEnergy(%rate,%val)
{//...
	
	if (%rate<50) %troubleState = 2;
	else if (%rate<75) %troubleState = 1;
	else %troubleState = 0;
	
	if (!isObject($songPositionList)) return;
   
	if (%troubleState != $prevSongSuffix)
	{	
		$songEmissionCount = $songPositionList.count();
		for (%i=0; %i<$songEmissionCount; %i++)
		{
         for (%stress=0; %stress<3; %stress++)
         {
            if (%stress!=%troubleState)
               if(isObject( $LevelMusic[%i,%stress]))
                  $LevelMusic[%i,%stress].setVolume(0.001);
         }
			if(!isObject( $LevelMusic[%i,%troubleState])) 
            $LevelMusic[%i,%troubleState] = sfxPlay($songPrefix @ %troubleState, $songPositionList.getKey(%i));
         else
            $LevelMusic[%i,%troubleState].setVolume(1.0);
		}
		$prevSongSuffix = %troubleState;
	}
}
(called every half second or so)

If there's a more proper way to pull that off, I'm sure I'm not the only one that'd like to hear about it should someone wish to weigh on in.