Game Development Community

Attaching sound to an Object

by Donald Teal · in Torque 3D Professional · 11/21/2009 (4:15 pm) · 8 replies

I would like to attach a sound to an object, or more percisly embed the sound call into the object. Similar to what was able to be done in TGEA as shown in this thread
www.garagegames.com/community/resources/view/10981
I have not been able to get a sound to be associated with an object in T3D. Not even sure what is possible in this aspect.


Thanks



#1
11/21/2009 (9:30 pm)
The process described in the resource still can be done just the same in T3D. You have to switch out the names for the datablocks though.

AudioDescription -> SFXDescription
AudioProfile -> SFXProfile

Also, the type field in SFXDescription is gone. There previously was the 'channel' field but starting with 1.1, the SFX system now uses hierarchical sound groups so the right field here is 'soundGroup'.

Setting up the datablocks is most easily done in the datablock editor and should make the process fairly self-explanatory.

The ShapeBase audio still works the same.
#2
11/21/2009 (11:30 pm)
HI Fixme,

I am still having an issue, with this,

here is the demoObject datablock
//---------------Audio Profile--------------------------------------------------

datablock SFXDescription(DemoObjectLooping3d)
{
   volume   = 1.0;
   isLooping= true;

   is3D     = true;
   ReferenceDistance= 5.0;
   MaxDistance= 60.0;
   sourceGroup = "AudioChannelDefault";
   parameters[0] = "";
   roomRolloffFactor = "0";
   
};

datablock SFXProfile(DemoObjectSound)
{
   filename    = "art/sound/testsnd.ogg";
   description = DemoObjectLooping3d;
   volume   = 1.0;
   preload = true;
};

//-------------End Audio Profile------------------------------------------------

datablock StaticShapeData(DemoObject)
{
  // The category variable determins where the item
  // shows up in the mission editor's creator tree.

  category = "Misc";
  shapeFile = "art/shapes/DemoObject.dts";
};

function DemoObject::onAdd(%this,%obj)
{
  // %obj is the object being added to the world
  // with %this datablock.  Start up a thread on the
  // new object.
  %obj.playThread(0,"boxspin");
  %obj.playAudio(0,DemoObjectSound);
}

function StaticShapeData::create(%block)
{
  // The mission editor invokes this method when it
  // wants to create an object of the given datablock
  // type.  You only need one of these methods for any
  // class/datablock type (in this case StaticShape).
  %obj = new StaticShape()
  {
     dataBlock = %block;
  };
  return(%obj);
}

there are no errors in the console but the sound will not play. to make sure the ogg file was good I put in a soundemmiter into the level and plays fine,


Am I forgetting something in converting paths or something?

#3
11/21/2009 (11:40 pm)

That last thing there with StaticShapeData::create looks suspiciously like a hook into the old TGEA world editor. AFAIK the current object building invokes such hooks (hadn't seen this in the thread and didn't look at the actual code drop).

Have you tried sticking an echo() in create() to see if it is actually invoked?

That would be my first guess.

Also, sort of as a preemptive measure against potential ass-kicking I might receive later for a bug I still haven't fixed, please make sure you're not running Torque with XAudio at the moment as the implementation has a bug that prevents sounds from starting.
#4
11/21/2009 (11:46 pm)

Argh... should more thoroughly read stuff. My rambling above about create() is pretty nonsense but still make sure the respective code gets executed actually.

Sorry, can't try out stuff myself at the moment.
#5
11/22/2009 (12:43 am)
@Fixme.

Nope not using XAudio

but I put in an echo and this is what I got in the console

scripts/server/demoobject.cs Line: 50 - parse error
>>> Advanced script error report. Line 50.
>>> Some error context, with ## on sides of error halt:
function DemoObject::onAdd(%this,%obj)

{

// %obj is the object being added to the world

// with %this datablock. Start up a thread on the

// new object.

%obj.playThread(0,"boxspin");

%obj.playAudio(0,DemoObjectSound);

}



function StaticShapeData::echo(create(%block))

##{##

// The mission editor invokes this method when it

// wants to create an object of the given datablock

// type. You only need one of these methods for any

// class/datablock type (in this case StaticShape).

%obj = new StaticShape()

{

dataBlock = %block;
>>> Error report complete
#6
11/22/2009 (12:51 am)

Sorry, my fault for not being very clear.

The echo() statement must be put inside the method, i.e.

function DemoObject::onAdd(%this,%obj)
{
  echo( "DEMOOBJECT::ONADD" );

  // %obj is the object being added to the world
  // with %this datablock.  Start up a thread on the
  // new object.
  %obj.playThread(0,"boxspin");
  %obj.playAudio(0,DemoObjectSound);
}

If you then see the message coming up in the log, you know the sound gets through alright to the shape and something else isn't right.

BTW, Mich has written really great docs for getting started with scripting. They can be found in the official T3D docs and I whole-heartily recommend them for getting to know the basics of TorqueScript (which is pretty easy to pick up even without a background in programming).
#7
11/22/2009 (1:16 am)
@Fixme,

Can I blame it being late on me putting the echo in the wrong spot?

But it seems the onadd section is not being executed. as my echo statement did not show up in the console.


#8
11/22/2009 (10:58 am)

Ok, tried it and had it working without problems.

It's probably not loading some resources there for you. Go and check the console.log for errors where it loads the file containing your script code.

Also make sure all paths are correct and point to the right files.