Data Realms Fan Forums http://45.55.195.193/ |
|
Can't get timers to work http://45.55.195.193/viewtopic.php?f=73&t=19121 |
Page 1 of 1 |
Author: | Laraso [ Sun Jun 27, 2010 9:58 pm ] |
Post subject: | Can't get timers to work |
Well, I've looked around at other lua's and I've looked around at some tutorials trying to figure out how to make timers, I was pretty sure I did it right, there was no errors or anything. This script is currently applied to a MOSRotating that is shot out of a cannon that I made to counter reflective stuff. Code: function Create(self) self.timeVar = Timer() end function Update(self) if self.timeVar > 20 then for actor in MovableMan.Actors do local diff = math.sqrt(math.pow((actor.Pos.X-self.Pos.X),2) + math.pow((actor.Pos.Y - self.Pos.Y),2)) if diff < 200 then actor.Vel = self.Vel actor.Health = actor.Health - 75 self.GibThis() end end end end Without the timer, it works perfect... But my actor gibs immediately and goes flying across the screen when I use it. That's why I tried adding a timer, but when I add a timer, the whole thing just stops working. I've even tried setting it so that when self.timeVar is greater than zero, the script activates, but still nothing. What am I doing wrong that prevents this timer from working correctly? |
Author: | CaveCricket48 [ Sun Jun 27, 2010 10:00 pm ] |
Post subject: | Re: Can't get timers to work |
Some timer info: To create a timer, make a variable and set it to the timer function: Code: self.animtimer = Timer() To reset the timer's count-up, use the reset function on the timer. Code: self.animtimer:Reset() To see if the timer is past a specific time (in MS) Code: if self.animtimer:IsPastSimMS(<time>) then And to check the current time on the timer. Code: self.animtimer.ElapsedSimTimeMS |
Author: | Petethegoat [ Sun Jun 27, 2010 10:02 pm ] |
Post subject: | Re: Can't get timers to work |
Replace self.timeVar > 20 with self.timeVar:IsPastSimMS(20). It is in milliseconds, so you probably want to increase that a bit. Also, self.GibThis() ought to be self:GibThis(). Edit: Ninja'd, somewhat. |
Author: | Laraso [ Sun Jun 27, 2010 10:03 pm ] |
Post subject: | Re: Can't get timers to work |
Wow, thanks for that fast reply! I see what I did wrong now, I should have used IsPastSimMS instead of >. @Petethegoat Yah, but I have it at 20 because the bullet is shot extremely fast so it should be a good enough distance away from you by then. And I have always used self.GibThis(), is it just improper to use a . in place of a : ? |
Author: | Petethegoat [ Sun Jun 27, 2010 10:19 pm ] |
Post subject: | Re: Can't get timers to work |
When you use GibThis(), you're calling a function, not a variable. It has no arguments so the () should always be empty, and just gibs whatever is passed to it. So self:GibThis() would gib self, logically enough. The main point is that it is a function, and not a variable, so you should use a colon. |
Author: | Grif [ Sun Jun 27, 2010 10:29 pm ] |
Post subject: | Re: Can't get timers to work |
To clarify that a bit more: A period indicates that something is either a property or a variable. In general, a period indicates either read only or read/write access to some kind of stored value. EG: self.Mass is a property of self, stored as a number variable. self.timer would be, technically, a pointer to the timer, stored as a reference from self. Functions, however, do something, rather than just reading or writing to stored variables. self:GibThis() is clearly differentiated as a function by the colon and the parenthesis (which house arguments on more complicated functions) It's good form syntactically, but it's also explicitly necessary. Semicolons on the end of most code blocks are good form, but not necessary, in case you weren't sure. anyways yeah you seem to have a pretty good grasp of lua already so, carry on! |
Author: | Laraso [ Sun Jun 27, 2010 10:48 pm ] |
Post subject: | Re: Can't get timers to work |
Yah, I know a lot of actionscript and they seem real similar, so that makes it easier. The ;'s I already know about, however, . and : I did not. Using actor.GibThis() was literally working without error until I was told about it, now it gives me function errors. ![]() I can't seem to get self:GibThis() to gib the MOSRotating, though. I am testing this particularly on the Reflective Robot and I am trying to make it so that it gibs before it has a chance to reflect it, exploding, sending it flying. But instead I just goes flying and the shell comes right back at me and explodes, sending my actor rocketing around the map until it hits something and gibs. Are MOSRotatings not able to be gibbed? Do I have to change it to something else like a TDExplosive? I was hoping to not have to use a TDExplosive. |
Author: | Petethegoat [ Sun Jun 27, 2010 10:54 pm ] |
Post subject: | Re: Can't get timers to work |
MOSRotating should gib fine. Are you getting any errors in the Lua console? |
Author: | Laraso [ Sun Jun 27, 2010 11:05 pm ] |
Post subject: | Re: Can't get timers to work |
Nope, and I checked the Reflective Robots reflection radius... It's 10 whole pixels. My scripts radius is (now) 50 pixels. That doesn't make any sense. I have even tried lowering the MOSRotatings velocity to 0 in both vectors when the script runs, but the same problem occurs and it gets reflected back at the same lightning speed it was shot with. |
Author: | Petethegoat [ Sun Jun 27, 2010 11:07 pm ] |
Post subject: | Re: Can't get timers to work |
Can we see the script? |
Author: | Laraso [ Sun Jun 27, 2010 11:16 pm ] |
Post subject: | Re: Can't get timers to work |
Code: function Create(self) self.timeVar = Timer() end function Update(self) if self.timeVar:IsPastSimMS(20) then for actor in MovableMan.Actors do local diff = math.sqrt(math.pow((actor.Pos.X-self.Pos.X),2) + math.pow((actor.Pos.Y - self.Pos.Y),2)) if diff < 50 then actor.Vel = self.Vel actor.Health = actor.Health - 20 self:GibThis() end end end end Pretty much the same as last time. Just made a few minor changes. |
Author: | Petethegoat [ Sun Jun 27, 2010 11:37 pm ] |
Post subject: | Re: Can't get timers to work |
Try commenting out the diff check and see if it works. If not, add prints everywhere to see exactly what it is stopping at. |
Author: | Laraso [ Mon Jun 28, 2010 1:42 am ] |
Post subject: | Re: Can't get timers to work |
Nope, doesn't work. I also don't know how to add a trace function in lua. Would it be trace("message"), or echo("message"), or something like that? |
Author: | TheLastBanana [ Mon Jun 28, 2010 1:56 am ] |
Post subject: | Re: Can't get timers to work |
print("message") is what you're looking for. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |