Databocks and onWorldLimit help
by Dean R Kohler II · in Torque Game Builder · 06/23/2010 (2:25 pm) · 4 replies
I am currently trying to create a factory method that will spit out enemies at a player in a random location across the x axis at the top of the screen out of view. I have set a datablock as follows for these:
My factory method is as follows:
And my onWorldLimit method is:
First, I have changed the world limits to sizes that can be debugged easily, so I know my datablocks are working properly. What isn't working are my callbacks to onWorldLimit. I've tried to debug with the console and it doesn't appear to fire. The proper callback property is set and I can echo the value of the objects on creation to the console. Everything is in place, but I just cannot get my worldlimit callback to fire.
Please help! What am I missing? Thank you.
datablock t2dSceneObjectDatablock(EnemyPlaneTemplate)
{
class = "enemyPlane";
imageMap = "testplaneImageMap";
frame = "1";
layer = "10";
size = "96 96";
flipY = "1";
WorldLimitMin = "-500 -500";
WorldLimitMax = "200 300";
WorldLimitMode = "NULL";
WorldLimitCallback = "1";
CollisionPolyList = "-0.928 -0.339 -0.020 -0.717 0.879 -0.354 0.938 -0.206 0.187 0.771 -0.025 0.791 -0.246 0.766 -0.972 -0.192";
CollisionActiveReceive = "1";
CollisionActiveSend = "1";
CollisionCallback = "1";
CollisionCircleSuperscribed = "0";
CollisionPhysicsReceive = "0";
CollisionPhysicsSend = "0";
minSpeed = 50;
maxSpeed = 200;
};My factory method is as follows:
function grassLevel::spawnPlane(%this)
{
%plane = new t2dStaticSprite()
{
scenegraph = %this;
};
%plane.setConfigDatablock(EnemyPlaneTemplate);
echo(%plane.getWorldLimit());
%plane.setPositionX(getRandom($Left_Bounds + %plane.getWidth(), $Right_Bounds - %plane.getWidth()));
%plane.setPositionY($Upper_Bounds);
%plane.setLinearVelocityY(getRandom(%plane.minSpeed, %plane.maxSpeed));
}And my onWorldLimit method is:
function enemyPlane::onWorldLimit(%this, %mode, %limit)
{
if(%limit $= "bottom")
{
echo("LimitReached!");
// %this.safeDelete();
}
}First, I have changed the world limits to sizes that can be debugged easily, so I know my datablocks are working properly. What isn't working are my callbacks to onWorldLimit. I've tried to debug with the console and it doesn't appear to fire. The proper callback property is set and I can echo the value of the objects on creation to the console. Everything is in place, but I just cannot get my worldlimit callback to fire.
Please help! What am I missing? Thank you.
#2
I did eventually give up and set the mode to KILL and widened the limits quite a bit.
My main concern right now is getting objects killed properly so that too much memory isn't being consumed since it's a recursive factory call.
Thanks for your response!
06/23/2010 (4:19 pm)
Well, the issue is that I wanted to handle it myself to make sure that only the bottom world limit was being reached. If the top, left or right limits are reached I really don't care. This will allow me more room and flexibility to script my objects for varied pathing without having to widen those limits too far.I did eventually give up and set the mode to KILL and widened the limits quite a bit.
My main concern right now is getting objects killed properly so that too much memory isn't being consumed since it's a recursive factory call.
Thanks for your response!
#3
Thank you for your efforts though, Patrick!
06/23/2010 (4:48 pm)
Ok, so it appears that setting the class in the datablock is what's causing the issue. I put it in the object declaration code instead and the callbacks were working properly.Thank you for your efforts though, Patrick!
#4
It seems like an odd resolution to the problem but it does make sense. If the enemyPlane class wasn't being assigned properly in the datablock (probably because the object didn't exist yet), then the enemyPlane namespace'd callback would never fire.
I love hating this engine. :)
Glad it's working for you.
06/23/2010 (6:57 pm)
My pleasure. It seems like an odd resolution to the problem but it does make sense. If the enemyPlane class wasn't being assigned properly in the datablock (probably because the object didn't exist yet), then the enemyPlane namespace'd callback would never fire.
I love hating this engine. :)
Glad it's working for you.
Torque Owner RollerJesus
Dream. Build. Repeat.
I couldn't get the callback to go either.
If all you're doing is killing the plane, then the KILL callback option will work for you. If you need to do something to the object as it dies there is an onSafeDelete callback that get's fired from the t2dSceneGraph namespace that will fire when the objects are deleted using KILL callback.
function t2dSceneGraph::onSafeDelete(%this, %object) { echo("onSafeDelete Called!"); }