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.
About the author
#2
This is what my trigger looks like in the scene file -
Here are my callbacks -
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?
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
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.
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.
Frantisek Smrcka
Nitromsoft Entertainment Renaissance