How to use the timer.delay function

I actually can’t figure out why my timer is going full speed this is my code:

function update_pps(self, handle, time_elapsed)
	points = points + pps
end

function update(self, dt)
	local timer = timer.delay(1, false, update_pps)
end

pps means points per second because I’m making a clicker game. the problem is that my counter just goes lightspeed when I use this code and if I do the code like this:

function update_pps(self, handle, time_elapsed)
	points = points + pps
end
timer.delay(1, false, update_pps)
function update(self, dt)
	
end

I get an error that says: ERROR:SCRIPT: Unable to create a timer, the lua context does not have a timer world

In your first code block, you are starting ~60 timers per second because you are starting them in the update cycle.

Your second code block would work if you initated the timer in the init() function.

Note that you should not use “timer” as a variable name, as you will be overwriting the timer() function.

2 Likes

okay thanks for the help :slight_smile: I sort of knew using the update function was part of it.