Page 1 of 1

Time

Posted: Sun Jul 17, 2016 8:11 pm
by Semeon
Hey,
Is it possible to perform a certain thing (function) for a specific time for example 2 seconds.
After some research I think it has to do something with frames but not quite sure please explain me how it is done thank you!

Re: Time

Posted: Sun Jul 17, 2016 10:15 pm
by steven777
update variable every revolution

tick = tick +1 -- updated every 1 cycle. 1/100 apx a second

adds time to tick..

tick = tick+dt -- updated every second

Re: Time

Posted: Sun Jul 17, 2016 10:17 pm
by steven777
this is basic and probably a really poor example but yea it works lol

function keeptime()
tick = tick +1
if tick > 9 and tick < 10
-- call a function
end

if tick > 10 then
tick = 0
end

end

remember that this is based on revolutions ( how many times the script is called )

change tick = tick +1 to tick = tick +dt if you want per second...

Re: Time

Posted: Mon Jul 18, 2016 2:58 am
by Inny
You can use cron.lua. It's a very simple library, all you need to do is on the love.update function, call update with the clock.

Code: Select all

myEvent = cron.after(5, function() print("This happens after 5 seconds") end)

function love.update(dt)
  myEvent:update(dt)
end
There are plenty of other timer libraries you can use, but the idea is the same for most of them, keep adding up the dt values that come from love.update.

Re: Time

Posted: Mon Jul 18, 2016 1:39 pm
by Tanner
HUMP's Timer lib has the function you want: http://hump.readthedocs.io/en/latest/ti ... mer.during