Page 1 of 1

Why does one of my timers take longer to go down to 0?

Posted: Tue Oct 10, 2017 8:11 am
by HedgeHog builder
It could just be my computer, but to me Follow_Timer seems to count down a lot slower than timer:

Code: Select all

	love.graphics.print(Follow_Timer,0,0)
	love.graphics.print(DirX,0,25)
	love.graphics.print(DirY,0,50)
	love.graphics.print(timer,150,0)
Both timers are going down by 1*dt, which I think should be the same for both the timers, yet timer counts down faster than Follow Timer
Both are set to 100 for the test.

When I observe the rate timer counts down, in the code section above, it appears to do it a lot faster..
It might just be my computer

Re: Why does one of my timers take longer to go down to 0?

Posted: Tue Oct 10, 2017 8:32 am
by bartbes
It's because you decrease 'timer' multiple times:

Code: Select all

for i,v in ipairs(Spawned_Units) do 
	timer = timer - (1*dt)
	if timer < 0 then
		timer = newTime
	end
	if timer < 1 then
		table.remove(Spawned_Units,i)
	end
end
So for every spawned unit you decrease the timer by 1 (per second). If there are 0 spawned units, timer doesn't run at all, with 1 spawned unit it will run as fast as Follow_Timer, and with 15 units it will run 15 times faster.