Time? - Detect When One Second Has Passed?(SOLVED)

Hi,

We need to add a timer to our game.
How would we register when one second has passed?
Thanks!

Jesse

In your scripts, dt represents the time between each frame. If you add them up then you can see how much time has passed in total since you began tracking.

The dt is in seconds. Its frame time each frame will usually be small if your game is running at a good frame rate.

function init(self)
	self.timer = 0
end

function update(self, dt)
	if self.timer < 1 then
		self.timer = self.timer + dt
		print(self.timer)
	end
	if self.timer >= 1 and not self.timer_flag then
		print("One second has passed!")
		self.timer_flag = true
	end
end
2 Likes

You can utilise built in timer https://www.defold.com/ref/timer/

3 Likes

Got it working, thanks!

1 Like