Game Development Community

add sound effect dropdown to "takesDamage" behavior?

by Dan Meister · in Game Design and Creative Issues · 08/17/2010 (5:19 am) · 3 replies

If someone could point me in the right direction, I am wondering if it is possible to modify the takesDamage behavior to include a field for a sound effect to play with the explosion, I have
if (!isObject(TakesDamageBehavior))
{
%template = new BehaviorTemplate(TakesDamageBehavior);

%template.friendlyName = "Takes Damage";
%template.behaviorType = "Game";
%template.description = "Set the object to take damage from DealsDamage objects that collide with it";

%template.addBehaviorField(health, "The amount of health the object has", int, 100);
%template.addBehaviorField(lives, "The number of times the object can lose all its health", int, 3);
%template.addBehaviorField(tintRedForDamage, "Tint the object red as it takes damage", bool, 0);
%template.addBehaviorField(respawnTime, "The time between death and respawn (seconds)", float, 2.0);
%template.addBehaviorField(invincibleTime, "The time after spawning before damage is applied (seconds)", float, 1.0);
%template.addBehaviorField(respawnEffect, "The particle effect to play on spawn", object, "", t2dParticleEffect);
%template.addBehaviorField(explodeEffect, "The particle effect to play on death", object, "", t2dParticleEffect);
%template.addBehaviorField(explodeSoundEffect, "The sound to play with explosion", object, "", $GuiAudioType);
}


I have tried some other things besides $GuiAudioType, but nothing seems to work, when I go to the toolset I have the dropdown field for explodeSoundEffect, but there is nothing available to select.
I have some sounds and looping music sec up in my audio datablock like this:
//background music
new AudioDescription(AudioLooping)
{
volume = 0.5;
isLooping= true;
//is3D variable defines whether or not the
//position of something in the world affects how
//the audio sounds
is3D = false;
//$GuiAudioType is a predefined audio type
//within Torque.
type = $GuiAudioType;
};

new AudioDescription(AudioNonLooping)
{
volume = 0.5;
isLooping= false;
is3D = false;
type = $GuiAudioType;
};

new AudioDescription(AudioNonLoopingLoud)
{
volume = 1.0;
isLooping= false;
is3D = false;
type = $GuiAudioType;
};

//this will be background music for first level
new AudioProfile(level1Audio)
{
filename = "~/data/audio/Acid_Trance.wav";
description = "AudioLooping";
preload = true;
};

new AudioProfile(xplosionAudio1)
{
filename = "~/data/audio/Explosion.wav";
description = "AudioNonLooping";
preload = true;
};

/*generates an audio profile on the fly.
An audio profile is an object that contains information
about the music or sound that you want to play. For example,
the filename for the music and the description (the name of
the audio template you are using with the music) */
function getAudio(%name, %type)
{
if (isObject(%name))
return;

new AudioProfile(%name)
{
filename = "~/data/audio/" @ %name @ ".ogg";
description = %type;
preload = false;
};
}

//functions that will play our audio
function playAudioLooping(%sound, %volume)
{
// get profile for background music and set default volume
getAudio(%sound, "AudioLooping");
alxSetChannelVolume($GuiAudioType, %volume);

//if another looping audio is playing, turn it off
if ($AudioLooping)
$AudioLooping = alxStopAll();
//play looping audio
$AudioLooping = alxPlay(%sound);
}

function playAudioNonLooping(%sound, %volume)
{
// get profile for background sound and set default volume
getAudio(%sound, "AudioNonLooping");
alxSetChannelVolume($GuiAudioType, %volume);

// if another background sound is playing, turn it off.
if ($AudioNonLooping)
$AudioNonLooping = alxStopAll();

// play background sound
$AudioNonLooping = alxPlay(%sound);
}

function playAudioNonLoopingLoud(%sound, %volume)
{
// get profile for sound effect
getAudio(%sound, "AudioNonLoopingLoud");

// play sound
AudioNonLoopingLoud.volume = %volume;
$AudioNonLoopingLoud = alxPlay(%sound);
}

/*
To use the audio engine, use these calls in your game:
1.playAudioLooping(%music, %volume)
2.playAudioNonLooping(%sound, %volume)
3.playAudioNonLoopingLoud(%soundeffect, %volume)
For example:
playAudioLooping("level1Audio", 1.0);
playAudioNonLooping("laserAudio1", 0.5);
playAudioNonLoopingLoud("xplosionAudio1", 1.0);
*/

Any ideas?

#1
08/19/2010 (3:47 am)
Got it figured out
#2
12/15/2012 (10:04 pm)
Just out of curiosity, what did you have to do? I'm setting up something very similar myself and it would be great if the user could select from a list of predefined sound effects from a dropdown when populating behavior data for an object.

I know it's an old thread but it's literally what I'm stuck on now and worth a shot!
#3
12/17/2012 (5:02 pm)
The field type should be "object" and the object type is "AudioProfile".

Really, though, you should add a sound effect behavior separate from the takes damage behavior - that way you don't have to modify every other behavior you want to use a sound effect with, you just add your sound effect behavior to it, too. As soon as T2D goes MIT you'll have access to behavior connections - a sort of internal signalling system between behavior instances on the same object. Then your takes damage behavior can raise a "TookDamage" signal and other behaviors can listen for it and react appropriately. Until then, you can define a method on the player class and have it call the respective behaviors' firing methods to set everything in motion, or about any other combination of different ways to achieve that.