behaviors unable to find objects declared in template
by Steven Sheffey · in Torque Game Builder · 01/04/2010 (11:13 pm) · 2 replies
Hey guys, I've been trying to figure out whats going on with my code. For some reason my behavior isn't seeing %this.projectile when it run my function "eShootsFocusBehavior::fire(%this)". Never had this issue after doing a good amount of self created behaviors. Did I make a mistake somewhere or overlook something? Can anyone point me in the right direction?
console is saying its unable to find anything for %this.projectile so it kicks out at the !isObject check.
I thought that it was declared in the behavior template :(
Thanks in advance!
Steven
if (!isObject(eShootsFocusBehavior))
{
%template = new BehaviorTemplate(eShootsFocusBehavior);
%template.friendlyName = "eShootsFocus";
%template.behaviorType = "Input";
%template.description = "Sprays objects out then homes in on trigger";
%template.addBehaviorField(eHomingTrigger, "The target the projectile will shoot to", object, "eHomingTrigger", t2dTrigger);
%template.addBehaviorField(projectile, "The projectile to clone and shoot", object, "vortex", t2dSceneObject);
//%template.addBehaviorField(player, "Player to attach trigger to", object, "player", t2dSceneObject);
%template.addBehaviorField(fireKey, "The key to fire the projectile with", keybind, "keyboard space");
%template.addBehaviorField(fireRate, "The rate to fire when the fire key is held down (seconds)", float, "1.00");
%template.addBehaviorField(projectileSpeed, "The speed of projectiles (world units per second)", float, "150");
%template.addBehaviorField(turnSpeed, "The speed to rotate at (degrees per second). Use 0 to snap", float, 0.0);
%template.addBehaviorField(rotationOffset, "The rotation offset (degrees)", float, -50.0);
}
function eShootsFocusBehavior::onBehaviorAdd(%this)
{
$enemy = %this.owner;
$ableToFire = true;
//if (isObject(moveMap))
//moveMap.bindObj(getWord(%this.fireKey, 0), getWord(%this.fireKey, 1), "fire", %this);
//$Eir = %this.erica;
}
function eShootsFocusBehavior::onBehaviorRemove(%this)
{
//if (isObject(moveMap))
//moveMap.unbindObj(getWord(%this.fireKey, 0), getWord(%this.fireKey, 1), %this);
}
function t2dSceneGraph::onUpdateScene(%this)
{
rangeTest(%this);
}
function rangeTest(%this)
{
$enemy.posX = enemy.getPositionX();
$enemy.posY = enemy.getPositionY();
$player.posX = player.getPositionX();
$player.posY = player.getPositionY();
%pDistanceX = mAbs($enemy.posX - $player.posX);
%pDistanceY = mAbs($enemy.posY - $player.posY);
%killRange = 10;
if(%pDistanceX <= %killRange && %pDistanceY <= %killRange)
{
$pInRange = true;
if ($ableToFire)
{
%this.projectile.schedule(1000, eShootsFocusBehavior::fire($projectile));
}
}
else
{
//echo ("Out of Range");
//echo (%this.fireKey);
$pInRange = false;
}
}
function eShootsFocusBehavior::fire(%this)
{
$ableToFire = false;
echo("Prepare to Fire");
sceneWindow2D.startCameraShake(5, 0.3);
//if (!%this.Owner.ActorBehavior.Alive)
//return;
/*if (%val == 0)
{
cancel(%this.fireSchedule);
return;
}*/
if (!isObject(%this.projectile))
return;console is saying its unable to find anything for %this.projectile so it kicks out at the !isObject check.
I thought that it was declared in the behavior template :(
Thanks in advance!
Steven
#2
01/05/2010 (12:33 pm)
Figured this out about an hour later. Basically changed the function t2dSceneGraph::onUpdateScene(%this) to function eShootsFocusBehavior::onUpdate(%this) and change my schedule (was missing a parameter) and all of a sudden everything worked!
Torque Owner Steven Sheffey
No Comp Studios
Edit: Forgot to mention that when I tested this code using the fireKey..everything worked correctly. So the problem I assume lies in the onUpdate or rangeTest functions. Hope that helps!