| Author | Message | 
        
			| djmorrsee 
					Joined: Fri May 02, 2008 2:48 am
 Posts: 56
   |   new to lua, and have a questionalright so im just now starting to learn lua, and ive been looking at the wiki and others peoples codes. if i wanted to have a cannon shoot a projectile that after a few seconds stopped in midair, would this lua script work? Code: function Create(self)self.LTimer = Timer();
 end
 
 function Update(self)
 if self.LTimer:IsPastSimMS(300) then
 self:vel = 0
 end
 end
I sort of bs'd it by what made sense in my head.  thanks in advance
 
 | 
		
			| Fri May 22, 2009 12:54 am | 
					
					   | 
	
	
		|  | 
	
			| Grif REAL AMERICAN HERO 
					Joined: Sat Jan 27, 2007 10:25 pm
 Posts: 5655
   |   Re: new to lua, and have a questionReplace self:Vel with this: That should work, but it's also possible to do this entirely within normal .ini modding, you know.
 
 | 
		
			| Fri May 22, 2009 1:43 am | 
					
					   | 
	
	
		|  | 
	
			| djmorrsee 
					Joined: Fri May 02, 2008 2:48 am
 Posts: 56
   |   Re: new to lua, and have a questionsweet i was close. thank you
 i figured there was a way to do it, but im doing this more as a learning thing.
 wouldnt the ini way require more gibbing then neccesary?
 
 or is there an easier way to do it? i tend to make things way harder then they need to be.
 
 
 | 
		
			| Fri May 22, 2009 1:50 am | 
					
					   | 
	
	
		|  | 
	
			| Grif REAL AMERICAN HERO 
					Joined: Sat Jan 27, 2007 10:25 pm
 Posts: 5655
   |   Re: new to lua, and have a questionAirResistance would slow your object to nothing if set high enough. Gibbing would be another way.
 But if you're doing it to learn by no means be stopped by me.
 
 
 | 
		
			| Fri May 22, 2009 2:08 am | 
					
					   | 
	
	
		|  | 
	
			| djmorrsee 
					Joined: Fri May 02, 2008 2:48 am
 Posts: 56
   |   Re: new to lua, and have a questionyeah, i learn best by doing. lots and lots of doing. Code: function Create(self)self.LTimer = Timer();
 end
 
 function Update(self)
 if self.LTimer:IsPastSimMS(300) then
 self:Vel = 0;
 end
 
 if self.LTimer:IsPastSimMS(600) then
 self:GibThis();
 end
 end
so this should be a working script? to have it shoot out, stop, then gib after a few seconds? Edit: and would it attach to the round or the MOSRotating the round is refering to? or does it matter?
 
 | 
		
			| Fri May 22, 2009 2:12 am | 
					
					   | 
	
	
		|  | 
	
			| Geti 
					Joined: Sun Jul 13, 2008 9:57 am
 Posts: 4886
 Location: some compy
   |   Re: new to lua, and have a questionVel is a vector, so you might want to try Code: self.Vel = Vector(0,0);self:GibThis() should work fine the way you're doing it. attach it to the MOSR.
 
 | 
		
			| Fri May 22, 2009 5:20 am | 
					
					     | 
	
	
		|  | 
	
			| TheLastBanana DRL Developer 
					Joined: Wed Dec 13, 2006 5:27 am
 Posts: 3138
 Location: A little south and a lot west of Moscow
   |   Re: new to lua, and have a questionAlso, remember, when you're calling a variable (something that you write to or read from) you use ".".  For example, actor.Vel.The : is used for functions, which you execute and do something for you, and end with a pair of brackets.  For example, actor:GibThis().
 
 
 | 
		
			| Fri May 22, 2009 5:25 am | 
					
					     | 
	
	
		|  | 
	
			| alfie275 
					Joined: Sun May 18, 2008 7:49 am
 Posts: 23
   |   Re: new to lua, and have a questionI thought ':' was for when you something passes itself as an argument to one of it's functions? So 'actor.GibThis(self);' would also work? 
 
 | 
		
			| Fri May 22, 2009 1:15 pm | 
					
					   | 
	
	
		|  | 
	
			| Duh102 happy carebear mom 
					Joined: Tue Mar 04, 2008 1:40 am
 Posts: 7096
 Location: b8bbd5
   |   Re: new to lua, and have a questionGrif wrote: AirResistance would slow your object to nothing if set high enough.You know, that variable doesn't work like I thought it would. I thought, setting it to 0.9 on a GlobalAccScalar = 0 MOSRot, that the MOSRot would slow down until it stopped, rather quickly (multiplying the MOSRot's velocity by 0.9 each frame), but what it did was slow down the MOSRot to about 10 or 5, but no further. I have the same thing happen when I set it to 1.0 Am I doing it wrong?
 
 | 
		
			| Fri May 22, 2009 2:00 pm | 
					
					   | 
	
	
		|  | 
	
			| Grif REAL AMERICAN HERO 
					Joined: Sat Jan 27, 2007 10:25 pm
 Posts: 5655
   |   Re: new to lua, and have a questionNo it's just Data doing lazy coding.
 I'm pretty sure it just multiplies by the divisor but eventually it goes past 16 digits (only 16 frames of calculation if it's 0.9) and then starts rounding, probably to 5-10 or so.
 
 Alternately it's just an infinite geometric series that will never quite stop.
 
 
 | 
		
			| Fri May 22, 2009 2:36 pm | 
					
					   | 
	
	
		|  | 
	
			| djmorrsee 
					Joined: Fri May 02, 2008 2:48 am
 Posts: 56
   |   Re: new to lua, and have a questionok, so according to what grif, geti, and last bannana said... Code: function Create(self)self.LTimer = Timer();
 end
 
 function Update(self)
 if self.LTimer:IsPastSimMS(100) then
 self.Vel = Vector(0,0);
 end
 
 if self.LTimer:IsPastSimMS(600) then
 self:GibThis();
 end
 end
^that is how you properly set up the script? EDIT: I answered my own question by testing it (imagine that) and it worked perfectly. thank you to everyone that helped. I'll Prolly have another question about something else here soon.
 
 | 
		
			| Fri May 22, 2009 5:00 pm | 
					
					   | 
	
	
		|  | 
	
	
		|  |