Page 1 of 1
Execute a function each 1 seconds (or more)
Posted: Sat Mar 10, 2012 2:51 pm
by xefhs
Hi,
I try to find the best way (in other words, optimized to save CPU) to execute a function each defined time.
Code: Select all
increaseCount(2) --Increase the count every 2 secs
Re: Execute a function each 1 seconds (or more)
Posted: Sat Mar 10, 2012 3:54 pm
by thelinx
Re: Execute a function each 1 seconds (or more)
Posted: Sat Mar 10, 2012 4:09 pm
by tentus
Or, if you don't need something quite that robust:
Code: Select all
function love.load()
timePassed = 0
timeLimit = 2
end
function love.update(dt)
timePassed = timePassed + dt
if timePassed > timeLimit then
timePassed = timePassed - timeLimit
doFunction()
end
end
Re: Execute a function each 1 seconds (or more)
Posted: Sun Mar 11, 2012 12:39 am
by xefhs
cron is very useful, and thanks for the explanations !