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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
HedgeHog builder
Prole
Posts: 15
Joined: Sat Aug 19, 2017 9:13 am

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

Post 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
Attachments
main.lua
(2.83 KiB) Downloaded 97 times
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

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

Post 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.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests