Trigger Troubles
by Don Hogan · in Torque Game Builder · 02/16/2006 (8:26 pm) · 2 replies
I'm having some strange issues with a trigger and I'm hoping someone can help me sort them out.
First things first, here's the script I'm using to make the trigger.
Then to execute my enemy spawning.
So, here are my issues:
1) The onEnter message does't always come when I cross the border, sometimes it's a few seconds after. Sometimes, the onLeave message echos right after the onEnter, even though I'm still in the trigger.
2) The onStay message never echoes, which is a real drag because that's where I really want the function to be.
3) Assuming I can get it to work in the onStay callback, how often does it check to see if the player is still there? Ideally, I'd like to have a set quantity of enemies in the base so it does run out, which I can do with a counter, but I don't want them all to dump at once because the callback fired at the same frequency as say, onSceneUpdate.
4) *edit* Got this one. Was a misplaced function bracket.
Any thoughts on these issues?
Thanks,
Don
First things first, here's the script I'm using to make the trigger.
// Make the bounding trigger
%trigger = new t2dTrigger() { scenegraph = N9_01SceneGraph; };
%trigger.setDebugOn(BIT(0));
%trigger.setPosition( %location );
%trigger.setSize( 120 120 );
%trigger.tag = "eBase";
%trigger.enterCallback = 1;
%trigger.stayCallback = 1;
%trigger.leaveCallback = 0;Then to execute my enemy spawning.
function t2dTrigger::onEnter(%this, %object)
{
echo("Enter:" @ %this.tag SPC %object.tag);
switch$( %object.tag )
{
// Player enters in trigger
case "player":
if ( %object.tag $= "player" )
schedule( 500, 0, "CreateEnemy", $eBase.getPosition, 225 );
else if ( %object.tag !$= "player" )
return;
}
}
function t2dTrigger::onStay(%this, %object)
{
echo("Stay:" @ %this.tag SPC %object.tag);
}
function t2dTrigger::onLeave(%this, %object)
{
echo("Leave:" @ %this.tag SPC %object.tag);
}So, here are my issues:
1) The onEnter message does't always come when I cross the border, sometimes it's a few seconds after. Sometimes, the onLeave message echos right after the onEnter, even though I'm still in the trigger.
2) The onStay message never echoes, which is a real drag because that's where I really want the function to be.
3) Assuming I can get it to work in the onStay callback, how often does it check to see if the player is still there? Ideally, I'd like to have a set quantity of enemies in the base so it does run out, which I can do with a counter, but I don't want them all to dump at once because the callback fired at the same frequency as say, onSceneUpdate.
4) *edit* Got this one. Was a misplaced function bracket.
Any thoughts on these issues?
Thanks,
Don
#2
to
Although, I would think it would be best to capture the enter and the leave instead of running the overhead of the stay every frame.
02/18/2006 (11:38 am)
Change%trigger.enterCallback = 1; %trigger.stayCallback = 1; %trigger.leaveCallback = 0;
to
%trigger.setEnterCallback( true ); %trigger.setStayCallback( true ); %trigger.setLeaveCallback( false );
Although, I would think it would be best to capture the enter and the leave instead of running the overhead of the stay every frame.
Torque Owner Don Hogan