Data Realms Fan Forums
http://forums.datarealms.com/

MovableManager:RemoveParticle() crashing
http://forums.datarealms.com/viewtopic.php?f=73&t=14926
Page 1 of 1

Author:  Darlos9D [ Sun May 24, 2009 10:33 pm ]
Post subject:  MovableManager:RemoveParticle() crashing

So I'm trying to use RemoveParticle() (a MovableManager function) to, well, remove a particle. In particular, a projectile. For one projectile, this function works fine. For another, it makes the game crash. I'm not really sure why, since the two scripts are quite similar and have the RemoveParticle() at the end of the script where nothing else could possibly be run on it afterward.

Here's the script that works:
Code:
function Update(self)
   local targetID = SceneMan:CastMORay(self.Pos, self.Vel, self.ID, -1, true, 0);
   if targetID ~= 255 and MovableMan:GetMOFromID(targetID).GetsHitByMOs then
      local impactLocation = Vector(0,0);
      SceneMan:CastFindMORay(self.Pos, self.Vel, targetID, impactLocation, -1, true, 0);
      
      local explosion = CreateAEmitter("D7AMSR Explosion Emitter");
      explosion.Pos = impactLocation;
      explosion.RotAngle = math.atan2(self.Vel.Y, self.Vel.X) * -1;
      MovableMan:AddParticle(explosion);
      
      MovableMan:RemoveParticle(self); <--- Does not crash code
   end
end

Here's the script that doesn't work
Code:
function Create(self)
   self.referenceMass = 150;
   self.maxDamage = 500;
   self.baseHealth = 100;
end

function Update(self)
   local targetID = SceneMan:CastMORay(self.Pos, self.Vel, self.ID, -1, true, 0);
   if targetID ~= 255 and MovableMan:GetMOFromID(targetID).GetsHitByMOs then
      local targetRootID = MovableMan:GetRootMOID(targetID);
      local target = MovableMan:GetMOFromID(targetRootID);
      
      local damage = 0;
      if target.Mass ~= 0 then
         damage = (self.referenceMass/math.abs(target.Mass)) * self.baseHealth;
      else
         damage = self.maxDamage;
      end
      
      if damage > self.maxDamage then
         damage = self.maxDamage;
      end
      
      for actor in MovableMan.Actors do
         if actor.ID == target.ID then
            actor.Health = actor.Health - damage;
         end
      end
      
      MovableMan:RemoveParticle(self); <--- For some reason crashes code
   end
end

I've tired RemoveMO() as well, which has the same results. I can only imagine that in the second script, the game is somehow trying to run functions on the particle after I've removed it, but I don't know what or why.

Author:  TheLastBanana [ Sun May 24, 2009 10:51 pm ]
Post subject:  Re: MovableManager:RemoveParticle() crashing

Generally, it's best to just use particle.Lifetime = 1. For whatever reason, the game has a tendency to crash when you use the removal functions.

Author:  numgun [ Sun May 24, 2009 10:52 pm ]
Post subject:  Re: MovableManager:RemoveParticle() crashing

Try self.Lifetime = 1
Same effect pretty much and works flawlessly.

EDIT: haha, TLB beat me to it :D

Author:  Darlos9D [ Sun May 24, 2009 10:54 pm ]
Post subject:  Re: MovableManager:RemoveParticle() crashing

Ah, how simple. Thanks.

Author:  mail2345 [ Sun May 24, 2009 11:25 pm ]
Post subject:  Re: MovableManager:RemoveParticle() crashing

RemoveMO works fine on items and actors.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/