Game Development Community

Do I have to create a new data block for every trigger area?

by Chris · in Torque Game Engine · 06/05/2009 (10:03 pm) · 4 replies

Hey guys, so I was curious... do I HAVE to make a new data block every time I want to for example call an onEnterTrigger? Currently I only know how to call an onEnterTrigger as follows:

function DefaultTrigger::onEnterTrigger(%this, %trigger, %intruder)
{
   // do something here
}

But this makes it so ANY trigger area assigned the DefaultTrigger data block has that same action associated with it. Is there any way to get around this without having to create hundreds of data blocks?

Thanks for any help guys!

#1
06/05/2009 (11:01 pm)
Which is exactly how it's supposed to work -- and does take some getting used to.

Make use of namespace methods and derive your different trigger types from the default.
#2
06/05/2009 (11:04 pm)
i prefer to make one subclass of the DefaultTrigger datablock called something like "MultiTrigger", and then code stuff sort of like this:

function MultiTrigger::onEnterTrigger(%this, %trigger, %obj)
{
   if (%trigger.hasPropertyFoo)
   {
      dealWithPropertyFooForObject(%obj);
   }

   if (%trigger.hasPropertyBar)
   {
      dealWithPropertyBarForObject(%obj);
   }

   // etc
}
and then you can set up triggers like this:
new trigger(trigger1)
{
   datablock = MultiTrigger;
   transform = stuff;
   hasPropertyFoo = true;
}

new trigger(trigger2)
{
   datablock = MultiTrigger;
   transform = stuff;
   hasPropertyFoo = true;
   hasPropertyBar = true;
}

and so on.
this way you have one datablock,
and you can mix-and-match different behaviours within each trigger.

there's probably a more object-oriented way to do this in torqueScript,
but imo now and then a big list of if()s is o-kay.
#3
06/05/2009 (11:23 pm)
... and here I was trying to keep things simple ;)

I like that Orion. That's sort of how I handled the different hit sounds, fx, explosions, debris, and wreckage states in Kaboom! Many new datablock fields and three (or four) staticshape methods to rule them all!

Never really though of applying that to triggers, kind of gives me ideas for other things now.
#4
06/06/2009 (7:00 am)
Now that a good idea for triggers, Orion. Will save a bit of time rather than typing it all in longhand (as it were).