%this.safeDelete() not working
by Arden · in Torque Game Builder · 08/24/2010 (5:00 pm) · 2 replies
Hiya Folks,
I got enemies dropping coins when shot by an arrow. I want the player to pick them up, but when the player gets close, the %this.safeDelete() doesn't seem to be woking and the coin stays on screen. Through the debug screen, I've also noticed that the collision gets detected, but it is looping very fast multiple times.
Both the player and the token are defined in a Datablock:
datablock t2dSceneObjectDatablock(playerDataBlock)
{
class = "Player";
size = "8.950 10";
Layer = 0;
vSpeed = 5.0;
hSpeed = 5.0;
CollisionActiveSend = "1";
CollisionActiveReceive = "0";
CollisionPhysicsSend = "1";
CollisionPhysicsReceive = "1";
CollisionCallback = "1";
CollisionPolyList = "-0.308 0.182 0.530 0.206 0.530 0.692 -0.327 0.692";
CollisionLayers = BIT(0) | BIT(1) | BIT(2) ;
};
datablock t2dSceneObjectDatablock(tokenDataBlock)
{
class = "Token";
size = "2.0 2.9";
Layer = 2;
//CollisionPolyList = "-0.367 0.147 0.275 0.162 0.301 0.452 -0.386 0.442";
CollisionActiveSend = "0";
CollisionPhysicsSend = "0";
CollisionActiveReceive = "1";
CollisionPhysicsReceive = "0";
CollisionCallback = "1";
CollisionLayers = BIT(0);
};
And here is the callback for the collision:
function Token::onCollision(%srcObj, %this, %srcRef, %dstRef, %time, %normal, %contactCount, %contact){
if(%srcObj.class = "player") //check if the object is colliding with the player
%this.safeDelete(); // delete the Tokenclass object.
echo ("Player has collided with the Token!");
}
Anything I'm doing wrong?
I got enemies dropping coins when shot by an arrow. I want the player to pick them up, but when the player gets close, the %this.safeDelete() doesn't seem to be woking and the coin stays on screen. Through the debug screen, I've also noticed that the collision gets detected, but it is looping very fast multiple times.
Both the player and the token are defined in a Datablock:
datablock t2dSceneObjectDatablock(playerDataBlock)
{
class = "Player";
size = "8.950 10";
Layer = 0;
vSpeed = 5.0;
hSpeed = 5.0;
CollisionActiveSend = "1";
CollisionActiveReceive = "0";
CollisionPhysicsSend = "1";
CollisionPhysicsReceive = "1";
CollisionCallback = "1";
CollisionPolyList = "-0.308 0.182 0.530 0.206 0.530 0.692 -0.327 0.692";
CollisionLayers = BIT(0) | BIT(1) | BIT(2) ;
};
datablock t2dSceneObjectDatablock(tokenDataBlock)
{
class = "Token";
size = "2.0 2.9";
Layer = 2;
//CollisionPolyList = "-0.367 0.147 0.275 0.162 0.301 0.452 -0.386 0.442";
CollisionActiveSend = "0";
CollisionPhysicsSend = "0";
CollisionActiveReceive = "1";
CollisionPhysicsReceive = "0";
CollisionCallback = "1";
CollisionLayers = BIT(0);
};
And here is the callback for the collision:
function Token::onCollision(%srcObj, %this, %srcRef, %dstRef, %time, %normal, %contactCount, %contact){
if(%srcObj.class = "player") //check if the object is colliding with the player
%this.safeDelete(); // delete the Tokenclass object.
echo ("Player has collided with the Token!");
}
Anything I'm doing wrong?
#2
P.S. I'll also make sure to use markuplite in future posts.
08/24/2010 (6:49 pm)
Kevin, it works, thanks for that. Now the Token disappears off screen. Part of my error was that I since the collision is received by the Token, I assumed the %srcObj should have been the player. Thanks for the Flag tip as well to avoid multiple collisions over the same object before it gets deleted. P.S. I'll also make sure to use markuplite in future posts.
Torque Owner Kevin James
1. The %scrObj is the token
2. %this is the %dstObj (player)
3. You want to set a flag like this:
function Token::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contact){ if(%dstObj.class $= "player" && !%scrObj.deleting) { echo ("Player has collided with the Token!"); %srcObj.deleting = true; %srcObj.safeDelete(); // delete the Tokenclass object. } }The flag prevent multiple hits while its trying to delete itself.