Execute a function each 1 seconds (or more)

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
User avatar
xefhs
Prole
Posts: 8
Joined: Fri Dec 09, 2011 7:17 am

Execute a function each 1 seconds (or more)

Post 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
Sorry about my English, I'm French.
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Execute a function each 1 seconds (or more)

Post by thelinx »

User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Execute a function each 1 seconds (or more)

Post 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
Kurosuke needs beta testers
User avatar
xefhs
Prole
Posts: 8
Joined: Fri Dec 09, 2011 7:17 am

Re: Execute a function each 1 seconds (or more)

Post by xefhs »

cron is very useful, and thanks for the explanations ! :megagrin:
Sorry about my English, I'm French.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 13 guests