Data Realms Fan Forums
http://45.55.195.193/

new to lua, and have a question
http://45.55.195.193/viewtopic.php?f=73&t=14852
Page 1 of 1

Author:  djmorrsee [ Fri May 22, 2009 12:54 am ]
Post subject:  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

Author:  Grif [ Fri May 22, 2009 1:43 am ]
Post subject:  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.

Author:  djmorrsee [ Fri May 22, 2009 1:50 am ]
Post subject:  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.

Author:  Grif [ Fri May 22, 2009 2:08 am ]
Post subject:  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.

Author:  djmorrsee [ Fri May 22, 2009 2:12 am ]
Post subject:  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?

Author:  Geti [ Fri May 22, 2009 5:20 am ]
Post subject:  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.

Author:  TheLastBanana [ Fri May 22, 2009 5:25 am ]
Post subject:  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().

Author:  alfie275 [ Fri May 22, 2009 1:15 pm ]
Post subject:  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?

Author:  Duh102 [ Fri May 22, 2009 2:00 pm ]
Post subject:  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?

Author:  Grif [ Fri May 22, 2009 2:36 pm ]
Post subject:  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.

Author:  djmorrsee [ Fri May 22, 2009 5:00 pm ]
Post subject:  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.

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