Re: Check a function, wait, then do something
Okay so let's see here. Now, I'm gonna try to be gentle.
1. SYNTAX SYNTAX SYNTAX.
It's not
necessary, in terms of your code running, because Lua is EXTREMELY forgiving with whitespace, but for the love of god, IF YOU ADD AN IF, TAB ONCE. It's a simple rule, but lord does it help with the legibility of everything (EVERYTHING) you do.
2. The function Update(self) cannot be called within itself. At all. Ever.
3. You can't put two function Create(self) lines. Well, you can, but
why?This:
Code:
function Create(self)
self.delayTimer = Timer();
self.delayInterval = math.random(0,300);
end
function Create(self)
self.fuzeTimer = Timer();
end
should never happen.
Why not just do this:
Code:
function Create(self)
self.delayTimer = Timer();
self.delayInterval = math.random(0,300);
self.fuzeTimer = Timer();
end
See how easy that is?
So here's code that should work:
http://pastebin.com/ZMFhkHMQNotice some things:
1. I fixed your syntax. Everything is tabbed intelligently; if you open a new logical statement, everything after that gets one additional tab. Then it's extremely easy to make sure you're closing everything: just line it all up. Also, use a good text editor; Notepad++ has
extremely useful function collapsing and syntax highlighting.
2. I reorganized your code somewhat. First to get rid of the completely unnecessary function Create/Update lines, which I really don't know why you put in there. In addition, I fixed some logical errors, and improved your distance finding code to use an engine function, which should be marginally faster. I made the distance check run half as fast, because one fifth of a game second is plenty frequent enough.
3. I removed your delay timer. It's not a bad way to approach the problem, but there's honestly an easier one: a coinflip with a somewhat skewed probability. Basically, I added a 33% chance for the round to detonate when it's within range. But that's going to reroll, probably at least twice, depending on exactly how fast your projectiles are traveling. This is a more efficient way to do it in terms of CPU cycles (meaning you can fire a whole hell of a lot of your flak rounds without much lag) and it'll probably work out just about the same.
If it's not bursting reliably enough near dropships, then you can try: A: lowering the upper bound on the random. Making it (1,2) will significantly increase the probability. Alternately, just lower the fuzetimer check rate to 150 or 100ms again.