View unanswered posts | View active topics It is currently Thu Dec 26, 2024 5:53 pm



Reply to topic  [ 11 posts ] 
 new to lua, and have a question 
Author Message
User avatar

Joined: Fri May 02, 2008 2:48 am
Posts: 56
Reply with quote
Post new to lua, and have a question
alright 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
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: new to lua, and have a question
Replace self:Vel with this:

Code:
self.Vel = 0;


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
Profile
User avatar

Joined: Fri May 02, 2008 2:48 am
Posts: 56
Reply with quote
Post Re: new to lua, and have a question
sweet 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
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: new to lua, and have a question
AirResistance 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
Profile
User avatar

Joined: Fri May 02, 2008 2:48 am
Posts: 56
Reply with quote
Post Re: new to lua, and have a question
yeah, 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
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: new to lua, and have a question
Vel 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
Profile WWW
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: new to lua, and have a question
Also, 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
Profile WWW

Joined: Sun May 18, 2008 7:49 am
Posts: 23
Reply with quote
Post Re: new to lua, and have a question
I 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
Profile
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post Re: new to lua, and have a question
Grif 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
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: new to lua, and have a question
No 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
Profile
User avatar

Joined: Fri May 02, 2008 2:48 am
Posts: 56
Reply with quote
Post Re: new to lua, and have a question
ok, 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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.068s | 14 Queries | GZIP : Off ]