How can i wait 10 seconds, call a function, wait 10 seconds again and call the same function? Like an endless loop to wait and call a function.
Still sorry for multiple posts :/
Waiting, calling a function and waiting again.
Waiting, calling a function and waiting again.
I can't come up with a good signature!
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: Waiting, calling a function and waiting again.
Create a timer, decrease the timer by dt each frame, once the timer is 0 or less, run the function and reset the timer. Rinse and repeat.
Re: Waiting, calling a function and waiting again.
Now how do i create the timer?
I can't come up with a good signature!
Re: Waiting, calling a function and waiting again.
Anxiety wrote:Now how do i create the timer?
Code: Select all
timer, called = 0, 0
function love.update(dt)
timer = timer + dt
if timer > 10 and called < 2 then
the_function(with, arguments)
timer = 0
called = called + 1
end
end
Code: Select all
Timer.addPeriodic(10, function() the_function(with, arguments) end, 2)
function love.update(dt)
Timer.update(dt)
end
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: Waiting, calling a function and waiting again.
A timer is just a variable holding a number, so:Anxiety wrote:Now how do i create the timer?
Code: Select all
function love.load()
timer = 10
end
function love.update(dt)
if timer <= 0 then
letsRunOurFancyFunction()
timer = 10
else
timer = timer - dt
end
end
Re: Waiting, calling a function and waiting again.
Ha. I thought i had to use something like timer.interval = 10000 and timer.tick but this easy, awesome!
I can't come up with a good signature!
Who is online
Users browsing this forum: Ahrefs [Bot] and 248 guests