Page 1  of 1  
			 [ 8 posts ]  
			 
		
	 
	
			
	
	
	
        
        
            Author 
            Message 
         
        
			
				 
				Awesomeness
				
				
					Joined:  Sat Jun 19, 2010 5:02 pmPosts:  331Location:  Mekkan
				
				 
			 
			
				
				 Lua script crashes game?
 
					
						So, I'm modifying the AI Lua so my actor has a little bar over his head.  This is the beginning of the script: (The rest isn't any different)
	
		 
	
	Code: 
--lolwut? airID = 0 goldID = 2 doorID = 4   -- Xenocronium grassID = 128 Obst = {R_LOW = 1, R_FRONT = 2, R_HIGH = 3, R_UP = 5, L_UP = 6, L_HIGH = 8, L_FRONT = 9, L_LOW = 10} WptType = {LAST = 0, UNKNOWN = 1, DROP = 2, AIR = 3} HumanAI = {} function CreateCode(self)    self.Bar = CreateMOSParticle("Bar Thing", "RogueRobots.rte");    self.Bar.Pos = self.AboveHUDPos + Vector(0,-20);    self.Bar.Frame = 10;    MovableMan:AddParticle(self.Bar); end function Update(self)    self.Bar.Pos = self.AboveHUDPos + Vector(0,-20); end function Create(self)        CreateCode(self);        self.Ctrl = self:GetController()        self.lateralMoveState = Actor.LAT_STILL    self.jumpState = AHuman.NOTJUMPING        self.deviceState = AHuman.STILL    self.lastAIMode = Actor.AIMODE_NONE    self.teamBlockState = Actor.NOTBLOCKED    self.SentryFacing = self.HFlipped    self.fire = false        self.AirTimer = Timer()    self.PickUpTimer = Timer()    self.ReloadTimer = Timer()    self.BlockedTimer = Timer()    self.TargetLostTimer = Timer()
 
 The bar floats over his head just fine.  However...  After a few seconds the game crashes without error.  What's wrong?
 
					 
			 
		 
		
			Mon Sep 19, 2011 2:32 am 
			
				
					
					
					
				  
			 
    	
		 
	
	
		 
	 
	
			
				 
				CaveCricket48
				
				
					Joined:  Tue Jun 12, 2007 11:52 pmPosts:  13144Location:  Here
				
				 
			 
			
				
				 Re: Lua script crashes game?
 
					
						You should check if the bar exists before setting its position.
					 
			 
		 
		
			Mon Sep 19, 2011 2:47 am 
			
				
					
					
					
				  
			 
    	
		 
	
	
		 
	 
	
			
				 
				TheLastBanana
				DRL Developer
				
					Joined:  Wed Dec 13, 2006 5:27 amPosts:  3138Location:  A little south and a lot west of Moscow
				
				 
			 
			
				
				 Re: Lua script crashes game?
 
					
						MOSParticles will automatically delete themselves after not moving for a while, even if they have a long lifetime. To work around this, you can set the MOSParticle's Age to 0 and ToDelete to false every update.
					 
			 
		 
		
			Mon Sep 19, 2011 3:01 am 
			
				
					
					
					
				    
			 
    	
		 
	
	
		 
	 
	
			
				 
				Awesomeness
				
				
					Joined:  Sat Jun 19, 2010 5:02 pmPosts:  331Location:  Mekkan
				
				 
			 
			
				
				 Re: Lua script crashes game?
 
					
						Worked perfect.  Thanks.
					 
			 
		 
		
			Mon Sep 19, 2011 3:17 am 
			
				
					
					
					
				  
			 
    	
		 
	
	
		 
	 
	
			
				 
				Awesomeness
				
				
					Joined:  Sat Jun 19, 2010 5:02 pmPosts:  331Location:  Mekkan
				
				 
			 
			
				
				 Re: Lua script crashes game?
 
					
						Um...  The bar that floats above my head settles when I move it through the ground 1/8 of the time D:
This is the start of the lua:
	
		 
	
	Code: 
--lolwut? airID = 0 goldID = 2 doorID = 4   -- Xenocronium grassID = 128 Obst = {R_LOW = 1, R_FRONT = 2, R_HIGH = 3, R_UP = 5, L_UP = 6, L_HIGH = 8, L_FRONT = 9, L_LOW = 10} WptType = {LAST = 0, UNKNOWN = 1, DROP = 2, AIR = 3} HumanAI = {} function CreateCode(self)    self.RechargeTime = 5000;        self.Bar = CreateMOSParticle("Bar Thing", "RogueRobots.rte");    self.Bar.Pos = self.AboveHUDPos + Vector(0,-20);    self.Bar.Frame = 11;    MovableMan:AddParticle(self.Bar);    self.BarTimer = Timer();    self.BarTimer.ElapsedSimTimeMS = self.RechargeTime;    self.CanFireLaser = true; end function Update(self)    --Make sure Mr. Bar doesn't dissappear    if not MovableMan:IsParticle(self.Bar) or self.Bar.PresetName ~= "Bar Thing" then       self.Bar = CreateMOSParticle("Bar Thing", "RogueRobots.rte");       self.Bar.Pos = self.AboveHUDPos + Vector(0,-20);       self.Bar.Frame = 11;       MovableMan:AddParticle(self.Bar);    end    self.Bar.ToDelete = false;    self.Bar.ToSettle = false;    self.Bar.Age = 0;                if self.ID == ActivityMan:GetActivity():GetControlledActor(0).ID then --If we are being controlled           self.Bar.Frame = math.min(10, math.floor(self.BarTimer.ElapsedSimTimeMS/(self.RechargeTime/10)));              if self.Bar.Frame == 10 then --If it's full          self.CanFireLaser = true;       else          self.CanFireLaser = false;       end           else --If wer're not being controlled:       self.Bar.Frame = 11;--Make the bar...  DISAPPEAR!/    end        self.Bar.Pos = self.AboveHUDPos + Vector(0,-20); end function Destroy(self)    self.Bar.ToDelete = true; end function Create(self)        CreateCode(self); ..
 
 And this is the ini for the bar:
	
		 
	
	Code: 
//Modelled from the heal effect. AddEffect = MOSParticle    PresetName = Bar Thing    Mass = 0.001    //GlobalAccScalar = -0.2 //Makes it float up    LifeTime = 5    RestThreshold = -500    HitsMOs = 0    GetsHitByMOs = 0    SpriteFile = ContentFile       FilePath = RogueRobots.rte/Sprites/Bar/Bar.bmp    FrameCount = 12    SpriteOffset = Vector       X = -6       Y = -2    //ScriptPath = RogueRobots.rte/Lua/Bar.lua    Atom = Atom       Material = Material          CopyOf = Air       TrailLength = 0    //Might add a glowy rectangle here :P    //ScreenEffect = ContentFile    //   FilePath = RogueRobots.rte/Effects/Glows/Blue.bmp    //EffectStartTime = 0    //EffectStopTime = 750    //EffectStartStrength = 0.5    //EffectStopStrength = 0
 
 I can't understand what's wrong  
 
					 
			 
		 
		
			Mon Sep 19, 2011 4:11 am 
			
				
					
					
					
				  
			 
    	
		 
	
	
		 
	 
	
			
				 
				Asklar
				Data Realms Elite
				
					Joined:  Fri Jan 07, 2011 8:01 amPosts:  6211Location:  In your office, earning your salary.
				
				 
			 
			
				
				 Re: Lua script crashes game?
 
					
						And if you use a MOSRotating instead of a MOSParticle? I did the bar thingie for a charging weapon, and I used a MOSRotating and I haven't got any problems at all.
					 
			 
		 
		
			Mon Sep 19, 2011 6:08 am 
			
				
					
					
					
				  
			 
    	
		 
	
	
		 
	 
	
			
				 
				CaveCricket48
				
				
					Joined:  Tue Jun 12, 2007 11:52 pmPosts:  13144Location:  Here
				
				 
			 
			
				
				 Re: Lua script crashes game?
 
					
						Make it pinned and ToSettle = false.
					 
			 
		 
		
			Mon Sep 19, 2011 11:36 am 
			
				
					
					
					
				  
			 
    	
		 
	
	
		 
	 
	
			
				 
				Awesomeness
				
				
					Joined:  Sat Jun 19, 2010 5:02 pmPosts:  331Location:  Mekkan
				
				 
			 
			
				
				 Re: Lua script crashes game?
 
					
						Setting the PinStrength worked perfectly.  Thanks a bunch 
 
					 
			 
		 
		
			Mon Sep 19, 2011 12:12 pm 
			
				
					
					
					
				  
			 
    	
		 
	
	
		 
	 
	
	
		 
	 
	
	
	
	
	
		
			
				  
			 
		
			 Page 1  of 1  
			 [ 8 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