Page 1 of 1
How do i wait until a certain condiction is given?
Posted: Tue Jan 31, 2017 9:49 pm
by arthurgps2
I've tried
timer=require'hump.timer'
timer.script(function(wait)
repeat
wait(0)
until condiction
end)
but it didn't worked. Please help me!
Re: How do i wait until a certain condiction is given?
Posted: Tue Jan 31, 2017 9:52 pm
by raidho36
You shouldn’t wait in a "while" loop, because it hangs the program until condition is met. Rather, you should check every update for your condition and if it's not there, don't take action (don't advance animation, don't move pieces, etc.)
Re: How do i wait until a certain condiction is given?
Posted: Tue Jan 31, 2017 11:20 pm
by 4aiman
A very stupid (and not-
that-precise) but working example.
Code: Select all
__POSTPONED = {}
function update_timers(dt)
for k,v in pairs(__POSTPONED) do
v.ttl = v.ttl-dt
if v.ttl<0 then
v.func(v.args)
__POSTPONED[k] = nil
end
end
end
function after(dt, func, ...)
__POSTPONED[#__POSTPONED+1] = {ttl = dt, func = func, args = ...}
end
Re: How do i wait until a certain condiction is given?
Posted: Tue Feb 07, 2017 6:18 pm
by xNick1
Easy way:
Code: Select all
timeWaited = 0
timeToWait = 10
function love.update(dt)
timeWaited = timeWaited + 1
if timeWaited >= timeToWait then
--do something here
end
end
love.update will loop endlessly,
that way you can get to know when a certain event happens.
In that case you wanna do something after 10 seconds
Re: How do i wait until a certain condiction is given?
Posted: Tue Feb 07, 2017 6:33 pm
by Robin
xNick1 wrote:Easy way:
That will do something after 10 frames, and then once every frame.
To make it go after 10 seconds, add dt instead of 1. To stop it from activating every frame after that, have a boolean flag that stops that from happening:
Code: Select all
timeWaited = 0
timeToWait = 10
timerActive = true
function love.update(dt)
timeWaited = timeWaited + dt
if timerActive and timeWaited >= timeToWait then
timerActive = false
--do something here
end
end