Data Realms Fan Forums
http://45.55.195.193/

Sudden crash when swapping actors
http://45.55.195.193/viewtopic.php?f=73&t=18809
Page 1 of 1

Author:  Areku [ Sun May 23, 2010 2:41 am ]
Post subject:  Sudden crash when swapping actors

Very well. I decided to try my hand at making a pilotable vehicle script, and after a few hours of ironing out bugs, came up with this:

Code:
function Create(self)

   self.IsPiloted = 0;
   self.Pilot = nil;
   self.DeathTimer = Timer();
   self.timer = Timer();
   self.IsDying = 0;
   

   
         
end



function Update(self)

if self.timer:IsPastSimMS(25) then

   if self.IsPiloted == 0 then
      if self:IsPlayerControlled() then
         ActivityMan:GetActivity():SwitchToActor(ActivityMan:GetActivity():GetPlayerBrain(self:GetController().Player),self:GetController().Player,self.Team);
      end
      
      for actor in MovableMan.Actors do
         if actor.ClassName == "AHuman" and actor.Mass < 300 then
            local avgx = actor.Pos.X - self.Pos.X;
                local avgy = actor.Pos.Y - self.Pos.Y;
               local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);    
            if dist < 30 then
               if actor:IsPlayerControlled() and actor:GetController():IsState(Controller.PIE_MENU_ACTIVE) and actor.AIMode == Actor.AIMODE_GOLDDIG then
                  self.Pilot = actor;
                  self.IsPiloted = 1;
                  ActivityMan:GetActivity():SwitchToActor(self,self:GetController().Player,self.Team);
                  actor.HitsMOS = false;
                  actor.GetsHitByMOS = false;
                  actor.AIMode = Actor.AIMODE_NONE;
                  
               end
            end
         end
      end
      
      self.AIMode = Actor.AIMODE_NONE;


   else
      

      if MovableMan:IsActor(self.Pilot) then
         self.Pilot.Pos.X = 0;
         self.Pilot.Pos.Y = 0;
         self.Pilot.Vel = Vector(0,0);
         self.Pilot.AngularVel = 0;   
         if self.Pilot:IsPlayerControlled() then
            ActivityMan:GetActivity():SwitchToActor(self,self:GetController().Player,self.Team);
         end
         if self.AIMode == Actor.AIMODE_GOLDDIG and self:IsPlayerControlled() and actor:GetController():IsState(Controller.PIE_MENU_ACTIVE)  then
            self.Pilot.Pos = self.Pos + Vector(5,5);
            self:FlashWhite(500);
            self.Pilot:FlashWhite(1000);
            self.Pilot.HitsMOS = true;
            self.Pilot.GetsHitByMOS = true;
            ActivityMan:GetActivity():SwitchToActor(self.Pilot,self:GetController().Player,self.Team);
            self.Pilot = nil;
            self.IsPiloted = 0;
         end
         if self.Health < 2 then
            self.Pilot.Pos = self.Pos + Vector(5,5);
            self:FlashWhite(500);
            self.Pilot:FlashWhite(500);
            self.Pilot.HitsMOS = true;
            self.Pilot.GetsHitByMOS = true;
            ActivityMan:GetActivity():SwitchToActor(self.Pilot,self:GetController().Player,self.Team);
            self.Pilot = nil;
            self.IsPiloted = 0;
            self.IsDying = 1;
         end
         


      else
         self.Pilot = nil;
         self.IsPiloted = 0;
      end
      
   end
   
   if self.IsDying == 0 then
      self.DeathTimer:Reset();
   end
   if self.Health < 2 then
      self.IsDying = 1;
   end
   if self.DeathTimer:IsPastSimMS(1000) then
      self:GibThis();
   end
   
self.timer:Reset();
end



end   


CC crashes instantly when I turn AI to gold dig on the pie menu. I assume it must be the game trying to refer to a null entry, but I can't see where the code would allow that to happen. It also gives no error message whatsoever, just stops working. Any thoughts on this?

Author:  CaveCricket48 [ Sun May 23, 2010 3:01 am ]
Post subject:  Re: Sudden crash when swapping actors

In the actor switching function after the gold dig check, you're trying to get the player who's controlling the vehicle when I think you inted to get the player of the pilot.

Author:  Areku [ Sun May 23, 2010 3:10 am ]
Post subject:  Re: Sudden crash when swapping actors

Why yes, you're right! That did the trick. Many thanks to ya, good sir.

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