Game Development Community

Unable to find trigger functions

by Steven Sheffey · in Torque Game Builder · 03/18/2010 (11:52 pm) · 4 replies

Hey guys, so I have a black hole that has a trigger mounted to it. The triggers job is to detect other black holes that enter. The code below should check to see if one entered then call the function spawnGravity2. Unfortunately, the console says: Unable to find function spawnGravity2. Am I missing something here?

function GravityBehavior::onEnter(%this, $shooter1, $blackHole, $blackHole1)
{		
	if ($blackHole)
		{
			%myBlackHole = %this.owner.getMountedParent();
			if (%myBlackHole == $blackHole)
			{
				echo("ITS ME");
			}
			else
			{
				echo("RUPTURE");
				$blackHole.spawnGravity2();	
			}
		}
}

function GravityBehavior::spawnGravity2(%this)
{
	$blackHoleDues = blackHoleDues1.cloneWithBehaviors();
		$blackHoleDues.setLayer(%this.getLayer());
		$blackHoleDues.setPosition(%this.getPosition());
		$blackHoleDues.setImmovable(true);
		//$blackHole.safeDelete();
		%this.gravTrigger.mount($blackHoleDues);		
}

Thanks for any insight or suggestions!

#1
03/19/2010 (12:12 am)
Try this instead:
$blackHole.getBehavior(GravityBehavior).spawnGravity2();
Let me know if it works!
#2
03/19/2010 (8:50 pm)
Hi William,

Ok so I tried out your code but then the console said

Unable to find object '0' attempting to call function 'spawnGravity2'
#3
03/19/2010 (9:51 pm)
Does $blackHole not have the GravityBehavior attached to it? If not, then your "spawnGravity2" function wouldn't make sense to be part of the behavior.

If this is the case, you have 2 options.

1) Change "function GravityBehavior::spawnGravity2( %this )" into "function spawnGravity2( %hole )" and call it as "spawnGravity2( $blackHole );". Make sure that you replace all instances of "%this" with "%hole".

OR

2) Give the $blackHole sprite a class (like "BlackHole"). Then change "function GravityBehavior::spawnGravity2( %this )" to "function BlackHole::spawnGravity2( %this )". Leave the "$blackHole.spawnGravity2();" alone in this case.

If this is not the case, let me know and we'll work through what the problem might be.

Edit: Ooh! Post 666!
#4
03/20/2010 (3:03 am)
Haha looks like evil Post 666 did the trick! Ended up using your second suggestion and everything works like a charm. Thank you very much will for taking the time to go through this with me. Gained some good knowledge!