major question: trouble shooting a bad behavior
by rennie moffat · in Torque Game Builder · 05/07/2010 (10:17 am) · 7 replies
HI I have a behavior, or two actually. One shoots out three objects "tracers". First one shoots, a scheduled delay, the second another scheduled delay and the third. Each is moving to a preset endDestination. This works fine.
Along the way to the end destination the tracers collide with a number of "tiles"(not t2dtileLayers). when each collision occurs a "blaster" is set in that tiles position. Simple right?! Well as I say, I have gotten it to work on a test level seamlessly however for some reason when I have loaded onto another level, on 2 separate occasions it only part works. The tracers shoot and reload fine, but the "blasters" do not set position... well they do on "some tiles", not all.
I have all collisions, names and classes working, set up right. I am wondering, with this code, if some one can point out something I am doing wrong, or could do better. thanks. I have spent a couple of days on this before asking. Anyhow, any help is appreciated.
Thanks.
I have placed echos which call for the blasters position and layer. the problem is the position. It is just not setting. As I say tho, for some cases they do set position appropriately using the exact same behavior but for most, they do not. very odd indeed. Collisions and physics are set appropriately on all so, what I am wondering is, going on what you know of this case, can anyone suggest troubleshooting tips that might work or help.
Thanks.
Along the way to the end destination the tracers collide with a number of "tiles"(not t2dtileLayers). when each collision occurs a "blaster" is set in that tiles position. Simple right?! Well as I say, I have gotten it to work on a test level seamlessly however for some reason when I have loaded onto another level, on 2 separate occasions it only part works. The tracers shoot and reload fine, but the "blasters" do not set position... well they do on "some tiles", not all.
I have all collisions, names and classes working, set up right. I am wondering, with this code, if some one can point out something I am doing wrong, or could do better. thanks. I have spent a couple of days on this before asking. Anyhow, any help is appreciated.
Thanks.
//// each tile has onCollision called.
if(%dstObject.class $= "cTT1Class")
%srcObject.setCTBlaster1();
///
function tileBehaviorCT1A::setCTBlaster1(%this)
{
%this.cTBlast1.setPosition(%this.tilePos);
}I have placed echos which call for the blasters position and layer. the problem is the position. It is just not setting. As I say tho, for some cases they do set position appropriately using the exact same behavior but for most, they do not. very odd indeed. Collisions and physics are set appropriately on all so, what I am wondering is, going on what you know of this case, can anyone suggest troubleshooting tips that might work or help.
Thanks.
About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
#2
If you're getting values for some, then they're probably left over from a previous call. Impossible to tell without seeing the whole behavior.
05/09/2010 (9:22 am)
Try echoing the values after you set them. They will always be null otherwise:%target = %this.temple.getPosition();
%this.distance1 = t2dVectorDistance(%target, %this.tile1Pos);
%this.distance2 = t2dVectorDistance(%target, %this.tile2Pos);
%this.distance3 = t2dVectorDistance(%target, %this.tile3Pos);
%this.distance4 = t2dVectorDistance(%target, %this.tile4Pos);
echo("%target" @ %target);
echo("%this.distance1 " @ %this.distance1);
echo("%this.distance2 " @ %this.distance2);
echo("%this.distance3 " @ %this.distance3);
echo("%this.distance4 " @ %this.distance4);If you're getting values for some, then they're probably left over from a previous call. Impossible to tell without seeing the whole behavior.
#3
But am I wrong to think that if I call a function, that within that function, if I ask the for the object temple position that it will return that position that temple happens to be at at that precise moment? So even if temple moves (after function is called) the %target will remain the same, unchanged until that function is called again later in time?
Also, could I email you, or would it be appropriate to post a massive behavior?
I might be able to learn some tips, as in how to cut down lines of code.
:::??
05/09/2010 (10:03 am)
ok I understand. But am I wrong to think that if I call a function, that within that function, if I ask the for the object temple position that it will return that position that temple happens to be at at that precise moment? So even if temple moves (after function is called) the %target will remain the same, unchanged until that function is called again later in time?
Also, could I email you, or would it be appropriate to post a massive behavior?
I might be able to learn some tips, as in how to cut down lines of code.
:::??
#4
You can post here but if it's extremely long it may get cut off... I'm not sure on the forum rules. Use pastie.org if you want.
05/09/2010 (9:24 pm)
Quote:that is correct.
But am I wrong to think that if I call a function, that within that function, if I ask the for the object temple position that it will return that position that temple happens to be at at that precise moment? So even if temple moves (after function is called) the %target will remain the same, unchanged until that function is called again later in time?
You can post here but if it's extremely long it may get cut off... I'm not sure on the forum rules. Use pastie.org if you want.
#5
at the top is a better explanation of what the behavior's purpose is. this may help. it is a bit of an essay, but it's to help you get the jist of my thinking.
http://www.pastie.org/953803
05/10/2010 (8:01 am)
ok thanks. I have posted it here.at the top is a better explanation of what the behavior's purpose is. this may help. it is a bit of an essay, but it's to help you get the jist of my thinking.
http://www.pastie.org/953803
#6
I think description here are a little messy, at least you confused my mind ^^, and usually this is why this kind of issue arises.
I try to summarize: essentially, you need a blaster appears (or move one already existent one) when an object (tile) collides with a bullet (tracer). So you can separate the problem into two goal, finding a position and setting a position. I assume you are able to set an object position, so the problem should be to find the correct position.
First of all, I suggest to use collisionGroup feature, avoiding the class type checking. I.e. avoid using something like if(%dstObject.class $= "cTT1Class")) for activating a code branch.
Then, you need to make the blaster appears. Assuming you have tile object inside the level looking similar to this:
this code will manage the tile collision with the bullet
With the %tilePosition you can create a new blaster at that position or move an already existent blaster to that position.
ALL this talking is about using tile object namespace (TileClass) for handling collision. If you want to use Behaviors to handle collisions, and a behavior is assigned to each tile object, the code is really similar but dramatically different
If you use both onCollision methods, please note TileCollisionBehavior::onCollision acts before TileClass::onCollision.
I hope this could be helpful fixing the issue,
happy scripting.
05/10/2010 (8:59 am)
Hi Rennie,I think description here are a little messy, at least you confused my mind ^^, and usually this is why this kind of issue arises.
I try to summarize: essentially, you need a blaster appears (or move one already existent one) when an object (tile) collides with a bullet (tracer). So you can separate the problem into two goal, finding a position and setting a position. I assume you are able to set an object position, so the problem should be to find the correct position.
First of all, I suggest to use collisionGroup feature, avoiding the class type checking. I.e. avoid using something like if(%dstObject.class $= "cTT1Class")) for activating a code branch.
Then, you need to make the blaster appears. Assuming you have tile object inside the level looking similar to this:
new t2dStaticSprite() {
imageMap = "tileImageMap";
frame = "0";
canSaveDynamicFields = "1";
class = "TileClass";
Position = "-4.324 -2.741";
size = "6.625 5.500";
CollisionActiveReceive = "1";
CollisionPhysicsSend = "0";
CollisionPhysicsReceive = "0";
CollisionGroups = "256";
CollisionCallback = "1";
mountID = "2";
};this code will manage the tile collision with the bullet
function TileClass::onCollision(%theTile, %theBullet, %srcRef, %dstRef, %time, %normal, %contacts, %points)
{
%tilePosition = %theTile.getPosition();
}With the %tilePosition you can create a new blaster at that position or move an already existent blaster to that position.
ALL this talking is about using tile object namespace (TileClass) for handling collision. If you want to use Behaviors to handle collisions, and a behavior is assigned to each tile object, the code is really similar but dramatically different
function TileCollisionBehavior::onBehaviorAdd(%this)
{
%this.owner.collisionCallback = true;
}
function TileCollisionBehavior::onCollision(%this, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
%tilePosition = %this.owner.getPosition();
}If you use both onCollision methods, please note TileCollisionBehavior::onCollision acts before TileClass::onCollision.
I hope this could be helpful fixing the issue,
happy scripting.
#7
thank you,
I am currently on some other things at the moment but will be going over this valuable resource.
cheers!
05/10/2010 (9:04 am)
great Giuseppe, thank you,
I am currently on some other things at the moment but will be going over this valuable resource.
cheers!
Torque Owner rennie moffat
Renman3000
in my echo returns I get no %this.distance1 nor %target. However I get returns for distances 2, 3 and 4.
echo("%target" @ %target); echo("%this.distance1 " @ %this.distance1); echo("%this.distance2 " @ %this.distance2); echo("%this.distance3 " @ %this.distance3); echo("%this.distance4 " @ %this.distance4); %target = %this.temple.getPosition(); %this.distance1 = t2dVectorDistance(%target, %this.tile1Pos); %this.distance2 = t2dVectorDistance(%target, %this.tile2Pos); %this.distance3 = t2dVectorDistance(%target, %this.tile3Pos); %this.distance4 = t2dVectorDistance(%target, %this.tile4Pos);how could that be? I set %this.tile1Pos, just as the others.
::::::::Frustrated.