Author Topic: [Coding Help] Callback for projectile lifetime expiration  (Read 860 times)

I'm trying to find a to detect when a BrickDeployProjectile is deleted due to its lifetime expiring, rather than from hitting an object.  How might I detect this?

Can't you rather track the building tool firing, get the projectile that way. When the lifetime is about to expire, check if it exists.

BrickDeployProjectile::onRemove should be called when it's deleted, then you'll need to check whether it timed out. Maybe that's as easy as this.lifetime <= 0?
« Last Edit: February 02, 2016, 07:41:38 AM by Zeblote »

Can't you rather track the building tool firing, get the projectile that way. When the lifetime is about to expire, check if it exists.

This is an unsatisfying and hacky way of solving the problem.  I'd only use that as a last resort.


BrickDeployProjectile::onRemove should be called when it's deleted, then you'll need to check whether it timed out. Maybe that's as easy as this.lifetime <= 0?

I've already tried packaging ::onRemove, yet it doesn't seem to get called, regardless of whether the projectile is destroyed from hitting an object or from having its lifetime expire.

Code: [Select]
package Planets
{
[...]
function BrickDeployProjectile::onRemove(%data, %this)
{
talk("testA");
Parent::onRemove(%data, %this);
}
[...]
};
activatePackage("Planets");

Projectile::onRemove directly works. It'll get called for every projectile which is lame, but there doesn't seem to be a better way.

That works, thanks for your help!