Game Development Community

Trigger callbacks are called onLevelLoaded() [RESOLVED]

by Frantisek Smrcka · in Technical Issues · 01/17/2012 (2:15 am) · 4 replies

Hi guys, I've discovered a strange behavior with triggers. I place them in a scene with all callbacks turned on and specify their functions in script using onEnter(), onLeave() and onStay() callbacks. They work just fine when collision occurs, however they also do something they're not supposed to. The callbacks are called automatically onLevelLoaded or onLoaded which absolutely ruins the function of the triggers. This way functions that are supposed to happen yet when a collision occurs are called right when the level is loaded and there's no escape from it. At least not that I know of. Am I doing something wrong or is it a bug? It happens in 1.7.5 for sure but I think I had the same issue with 1.7.6 but I'll double check that. Any help will be greatly appreciated.

#1
01/17/2012 (4:29 am)
Ok, so this is really weird. I figured out what causes such unusual behavior with the triggers and guess what, it's their size. I've tried many different combinations and it looks like triggers work as supposed only as far as their size is less or equal to 89x98. Any size higher (either width or height) causes the above described behavior. Could someone please explain that to me? And is there a way of changing this limit cause 89x98 is rather too small for my purpose. Thanks in advance...
#2
01/17/2012 (12:21 pm)
I can't reproduce this - here is my super simple test case:

This is what my trigger looks like in the scene file -
new t2dTrigger() {
      StayCallback = "1";
      canSaveDynamicFields = "1";
      class = "StartTrigger";
      Position = "-0.497 205.000";
      size = "1034.764 370.000";
      CollisionActiveSend = "1";
      CollisionActiveReceive = "1";
         mountID = "2";
   };

Here are my callbacks -
function StartTrigger::onEnter(%this, %object)
{
   echo(" -- StartTrigger::onEnter()");
   %object.BlendColor = "0.5 1.0 0.1 1.0";
}

function StartTrigger::onStay(%this, %object)
{
   echo(" -- StartTrigger::onStay()");
}

function StartTrigger::onLeave(%this, %object)
{
   echo(" -- StartTrigger::onLeave()");
   %object.BlendColor = "1.0 1.0 1.0 1.0";
}

This behaves as designed. I created a static sprite and added keyboard movement controls to it, then moved it into and out of the trigger. The trigger callbacks were not called on level load. As you can see from the code in the first block my trigger is far larger than 89x98.

Perhaps there is something else interacting with your trigger code? Is there a namespace clash somewhere?
#3
01/17/2012 (1:41 pm)
I had this problem a while back too and it was because another object was activating the trigger. You can find out exactly what is causing this by "echo"ing the %object's datablock in the onEnter function. If you only want this to activate for the player, you'll need to check for that at the beginning of your trigger functions.
#4
01/20/2012 (6:01 am)
Ok guys, so it seems I completely misunderstood how trigger callbacks work. I assumed that I can input the desired object's name instead of the default %object parameter but yet now I realized that it doesn't work that way. Thank you both though for navigating me the right direction.

Everything makes sense now and the size limit is obviously nonsense, it was called by another object I only didn't know it was responding to all colliding objects.

Setting this thread as resolved. Thanks again.