Game Development Community

Why isn't ::onTrigger working??

by Dean · in Torque Game Engine · 06/19/2007 (11:20 am) · 7 replies

I'm simply trying to get onTrigger to work. here's a simple test function i'm using:

function LightMaleHumanArmor::onTrigger(%this,%obj,%trigger,%state)
{
	echo("LightMaleHumanArmor trigger!");
}

I have an animation of a guy running and I spaced triggers 1-6 in it just as a test.
to begin with, I tested my animation triggers by adding this to player.cpp

for (S32 i = 0; i < 7; i++)
if (mShapeInstance->getTriggerState(i))
 Con::printf("triggered %d", i);

and this successfully prints to my console when the animation triggers hit.


now, the code that actually sends "onTrigger" is:

if (move && mDataBlock && isServerObject()) {

      for (S32 i = 0; i < MaxTriggerKeys; i++) {

         if (move->trigger[i] != mTrigger[i]) {
            mTrigger[i] = move->trigger[i];
            char buf1[20],buf2[20];
            dSprintf(buf1,sizeof(buf1),"%d",i);
            dSprintf(buf2,sizeof(buf2),"%d",(move->trigger[i]?1:0));
            Con::executef(mDataBlock,4,"onTrigger",scriptThis(),buf1,buf2);
         }
      }
   }

now, in the line " if (move->trigger[i] != mTrigger[i])" , if I change != to ==, it will constantly send "onTrigger" and my function LightMaleHumanArmor::onTrigger works. so now I know its the if statement that keeps onTrigger from working. I noticed that both move->trigger[i] and mTrigger[i]) are ALWAYS 0.

So now my question is, do you have any idea WHY can't I get onTrigger to work?

#1
06/19/2007 (11:53 am)
I read someplace you may need to add

function StaticShape::onTrigger(%this, %obj, %state)
{
     %this.getDatablock().onTrigger(%this, %state);
}
#2
06/19/2007 (12:47 pm)
I looked up the threads you were talking about. I added that function to triggers.cs but it's still not working. I'm guessing that doesn't work with players... i dont know. i tried
function Player::onTrigger(%this, %obj, %state)
	{
	%this.getDatablock().onTrigger(%this, %state);
	echo("running new function");
	}

but i'm still not getting any kind of response from my triggers :/ And I can't move forward in my project until i get this figured out. Is it possible I created my model or animations improperly? I'm completely stumped.
#3
06/20/2007 (6:41 am)
Do you get anything from the jump and fire trigger ?
And try to use Armor::onTrigger, what version of the engine are you using ?
above you have LightMaleHumanArmor is this correct ?

And a off topic one how can you be on the privat forum without no licence ?
#4
06/20/2007 (6:54 am)
This is the post I read (it seems to be the same problem your having):

http://www.garagegames.com/mg/forums/result.thread.php?qt=34607


I'm not exactly sure what your trying to do.
#5
06/20/2007 (8:18 am)
I'm trying to get the triggers i put in the animations to call back so i can run other functions when they trigger. similar to how footsteps are triggered. I can get print to text on the triggers but it wont send callbacks on them.
#6
06/20/2007 (8:27 am)
Does this resource help? You could just modify the part that triggers a sound to do whatever you want.
#7
06/20/2007 (9:15 am)
Oooh, yeah that might be what i'm looking for :) . i'll try it right now.


edit1: Not working. but at least I think I know what the problem is now...

The triggers are only hitting on the ghost. if i use if (!isGhost()), whenever i use mShapeInstance->getTriggerState, it will always give me 0. I don't know what to do about that :/



edit2: heh, well at least I know how to get my callbacks now. I ran the trigger test on the client instead of the server
if (mShapeInstance && isGhost()){
		for (U32 i = 1; i < 33; i++){
		   if (mShapeInstance->getTriggerState(i)){
			   char slot[2];  
			   dSprintf(slot,sizeof(slot),"%d",i);
			   Con::executef(mDataBlock,3,"onAnimationTrigger",scriptThis(),slot);
		   }
	   }
   }

the only problem that it's working from the ghost instead of the server, so couldnt that potentially cause some client/server problems for me in the future?