Game Development Community

Trigger will not stop looping animation and sound

by Justin Woods · in Torque Game Engine · 03/24/2006 (12:50 am) · 10 replies

The title for this post may be a bit misleading, but it is close.

Basically I have a DTS object and a trigger sitting on top of each other. The DTS object has a sequence embedded in it, and the trigger plays the noise. When you walk into these items, even if you leave, they don't stop animating and wailing. Here are the relevant fragments of code. Please help!

NOTE: You will see other attempts I made at doing the same thing in my comments. Those obviously didn't work as good, or didn't work at all. I just left them there so you guys could see the different aproaches I took.

function ItemData::create( %data )
{
	echo( "ItemData::create for Plant called Wickward----------" );

	%obj = new Item()
	{
		dataBlock = %data;
		rotate = false;
		static = true;
	};

	return %obj;
}

function Wickward::onAdd(%this,%obj)
{
	%obj.playThread(0,"idle1");
}

function Wickward::onCollision( %this, %obj, %col )
{
    echo( "Wickward::onCollision called Wickward-----------" );
if (%col.getType() & $TypeMasks::PlayerObjectType) 
{
	//$mySound = alxCreateSource("Sound",expandFilename("~/data/sound/wickward_alert.wav"));
	//alxPlay ($mySound);

	%obj.playThread(0,"alert");
	%obj.playAudio(0, Wickwardnoise);
}
}

datablock TriggerData(WickwardTrigger)
{
    tickPeriodMS = 100;
};



function WickwardTrigger::onEnterTrigger( %this, %trigger, %obj )
{
     echo( "The Sound Has been CALLED!!!!11111" );
     %obj.playAudio(0, Wickwardnoise);
     //serverPlay3D(Wickwardnoise,%obj.getTransform());
}

function WickwardTrigger::onLeaveTrigger(%this, %trigger, %Obj)
{
    Parent::onLeaveTrigger(%this,%trigger,%obj);
    %obj.stopAudio(0);
}

datablock AudioProfile(Wickwardnoise)
{
	filename    = "~/data/sound/wickward_alert.wav";
	description = AudioDefaultLooping3d; //AudioClose3d;
	preload = false;
	isLooping = true;
};

#1
03/24/2006 (5:37 am)
%obj.stopAudio(0);
Will only stop audio on the client (I think).

Try using
alxStop($WickwardHandle);

You might also want to change the AudioDescription to something unique to what you're doing here rather than a default profile used by lots of common things.

Example
datablock AudioDescription(WickwardObject)
{
   volume   = 1.0;
   isLooping= true;
   is3D     = true;
   [b]type     = $wickwardAudioType;[/b]
};


datablock AudioProfile(WickwardNoise)
{
filename = "~/data/sound/wickward_alert.wav";
description = WickwardObject;
preload = false;
isLooping = true;
};

Then you can use
alxStop($wickwardHandle);

To stop only sounds that use above AudioDescription.

P.S.

Don't forget to declare
$WickwardAudioType  = 4;
in client/scripts/audioProfiles.cs with the rest of them.
#2
03/24/2006 (10:53 am)
This method did not work. I also forgot to say that all of this code is in a new file called server/scripts/plant.cs.

Remember, it isn't only the audio that won't stop, it is the animation sequence as well.
#3
03/24/2006 (11:10 am)
What about calling stopThread in onLeaveTrigger?
#4
03/24/2006 (11:22 am)
I'm not sure why that would work, as the trigger and collision on the DTS are not linked, and I called the playThread in the collision, because I'm not sure how to have a trigger remotely play a thread on a DTS object.

Why is this so complicated? I'm not a very experienced TorqueScript user, but it seems like if I had a lot of experience this would be something very easy to do. Why is it so hard?
#5
03/24/2006 (11:59 am)
It's not that hard. You can link the object to your trigger in the mission editor by adding a dynamic field to the trigger that holds the objects name, and then reference it in script with %trigger.objectRef.playThread . You can even code the onAdd function of the trigger to spawn and link the shape on mission loadup where the trigger is located.
#6
03/25/2006 (12:37 am)
Paul, could you elaborate on this a bit more? I'm not entirely sure what a dynamic field is like, and what exactly you are saying. Could you provide an example using my code? That would be helpful, as I have to do something similar in a few different objects.
#7
03/25/2006 (8:28 pm)
I guess what you are saying is pretty simple in theory. I read up on dynamic fields, and I understand how to add them to the engine now.

The only problem with this approach goes back to my original problem - how do I reference a specific object if their mission editor numbers change on every mission load. For example, the wickward that I wanted to put into this field was number 1582 in my engine, but it is 1745 the next time, how do I manage that?

I think if I had known the answer to that a while back, I may have eventually figured this out.
#8
03/25/2006 (8:58 pm)
Here look at something like this and see if it makes sense to you:
WickwardTrigger::onAdd(%this, %trigger){

   %ss = new (StaticShape)() {
      dataBlock     = yourSSDatablock;
   };
   %ss.setTransform(%trigger.getTransform());
   %trigger.objRef = %ss;

}

WickwardTrigger::onEnter(%this, %trigger, %obj){

%trigger.objRef.playThread(0,"alert");

}
#9
03/27/2006 (10:25 pm)
Paul, this solution (with some obvious tweaking) did not work. In fact, when I try to drop the trigger into the world, it won't even appear anymore. Also, isn't the function Triggername::onEnterTrigger? In any case, making some of the changes and calling "yourSSDatablock" "Wickward" did not produce a result.

Any ideas?
#10
03/30/2006 (11:44 pm)
I'm still having troubles with this. I have not been able to get any of these solutions to work. The latest one from Paul seems promising, but there is something not allowing the trigger to even be placed in the world.