View unanswered posts | View active topics It is currently Sat Apr 20, 2024 4:59 am



Reply to topic  [ 5 posts ] 
 MovableManager:RemoveParticle() crashing 
Author Message
User avatar

Joined: Mon Jul 16, 2007 9:50 am
Posts: 1512
Location: Tallahassee, FL
Reply with quote
Post 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.


Sun May 24, 2009 10:33 pm
Profile YIM
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post 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.


Sun May 24, 2009 10:51 pm
Profile WWW

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post Re: MovableManager:RemoveParticle() crashing
Try self.Lifetime = 1
Same effect pretty much and works flawlessly.

EDIT: haha, TLB beat me to it :D


Sun May 24, 2009 10:52 pm
Profile
User avatar

Joined: Mon Jul 16, 2007 9:50 am
Posts: 1512
Location: Tallahassee, FL
Reply with quote
Post Re: MovableManager:RemoveParticle() crashing
Ah, how simple. Thanks.


Sun May 24, 2009 10:54 pm
Profile YIM
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: MovableManager:RemoveParticle() crashing
RemoveMO works fine on items and actors.


Sun May 24, 2009 11:25 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.167s | 15 Queries | GZIP : Off ]