Author |
Message |
Mind
Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
|
Oh look! Another Lua topic because I can't solve lua myself
Wow, I need to really solve this myself, but i can't. I want speed to continually increase, but for some reason I don't think it's working. Code: Code: function Create(self) self.ToDelete = false; self.timerl = Timer(); end function Update(self) local speed = 1.0 if self.timerl:IsPastRealMS(50) then speed = speed * 1.1 self.timerl:Reset(); end end My goal is to continually increase "speed". I don't think it is, but i could be wrong.
|
Fri Jul 03, 2009 7:46 pm |
|
|
zalo
Joined: Sat Feb 03, 2007 7:11 pm Posts: 1496
|
Re: Oh look! Another Lua topic because I can't solve lua myself
That's because every update you are defining the speed as 1.0.
|
Fri Jul 03, 2009 7:56 pm |
|
|
Mind
Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
|
Re: Oh look! Another Lua topic because I can't solve lua myself
zalo wrote: That's because every update you are defining the speed as 1.0. So how would you make it to update "speed" every time the timer is past whatever MS? Better yet, how would you get it to even work?
|
Fri Jul 03, 2009 7:59 pm |
|
|
piipu
Joined: Mon Jun 30, 2008 9:13 pm Posts: 499 Location: Finland
|
Re: Oh my! Another Lua topic
What Zalo said. Also, what is speed supposed to do?
|
Fri Jul 03, 2009 8:05 pm |
|
|
Mind
Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
|
Re: Oh my! Another Lua topic
piipu wrote: What Zalo said. Also, what is speed supposed to do? Just a variable I'm gonna use in a code. So how will i get it to work in multiplying it by 1.1 every 50 MS?
|
Fri Jul 03, 2009 8:06 pm |
|
|
mail2345
Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
|
Re: Oh look! Another Lua topic because I can't solve lua myself
Global variable or not? If it's just for it's self, then: Code: function Create(self) self.ToDelete = false; self.timerl = Timer(); self.speed = 1.0 end function Update(self) if self.timerl:IsPastRealMS(50) then self.speed = self.speed * 1.1 self.timerl:Reset(); end end If it's global, I need the code for both objects, and the preset and class names.
|
Fri Jul 03, 2009 8:31 pm |
|
|
ProjektTHOR
Banned
Joined: Tue Feb 27, 2007 4:05 pm Posts: 2527
|
Re: Oh look! Another Lua topic because I can't solve lua myself
I guess these guys aren't explaining the problem to you adequately. The issue is that when you call your function, one of the first things that it does is set the property "speed" to 1.0. Every time you call that function, speed becomes "1.0," regardless of its previous attribute. What mail just suggested was that the property becomes a global (read: public) property and is set to 1.0 before the execution of the function. Does that make sense? also, use
|
Fri Jul 03, 2009 9:14 pm |
|
|
Mind
Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
|
Re: Oh look! Another Lua topic because I can't solve lua myself
Oh. Okay, thanks But what if I put a like in create? Would that still set it to 1.0 every sim update? Just curious.
|
Sat Jul 04, 2009 1:14 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Oh look! Another Lua topic because I can't solve lua myself
function Create(self)
runs when the particle in question is created (imagine that)
function Update(self)
runs the full script every sim update frame
function Destroy(self)
runs when the particle in question is destroyed
if you define the variable in create, you're then allowed to reference and use it properly in update. in this case, since it's defined in create, you can do all your multiplication in update and it'll work a-ok
ps, there's no *=,+=, etc, lua's weird that way.
|
Sat Jul 04, 2009 1:43 am |
|
|
|