Data Realms Fan Forums http://45.55.195.193/ |
|
Oh look! Another Lua topic because I can't solve lua myself http://45.55.195.193/viewtopic.php?f=73&t=15706 |
Page 1 of 1 |
Author: | Mind [ Fri Jul 03, 2009 7:46 pm ] |
Post subject: | 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. |
Author: | zalo [ Fri Jul 03, 2009 7:56 pm ] |
Post subject: | 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. |
Author: | Mind [ Fri Jul 03, 2009 7:59 pm ] |
Post subject: | 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? |
Author: | piipu [ Fri Jul 03, 2009 8:05 pm ] |
Post subject: | Re: Oh my! Another Lua topic |
What Zalo said. Also, what is speed supposed to do? |
Author: | Mind [ Fri Jul 03, 2009 8:06 pm ] |
Post subject: | 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? |
Author: | mail2345 [ Fri Jul 03, 2009 8:31 pm ] |
Post subject: | 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. |
Author: | ProjektTHOR [ Fri Jul 03, 2009 9:14 pm ] |
Post subject: | 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 Code: self.speed *= 1.1 |
Author: | Mind [ Sat Jul 04, 2009 1:14 am ] |
Post subject: | Re: Oh look! Another Lua topic because I can't solve lua myself |
Oh. Okay, thanks But what if I put a like Code: local speed = 1.0 |
Author: | Grif [ Sat Jul 04, 2009 1:43 am ] |
Post subject: | 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. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |