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!
How do i wait until a certain condiction is given?
- arthurgps2
- Prole
- Posts: 5
- Joined: Tue Jan 31, 2017 9:12 pm
- Contact:
Re: How do i wait until a certain condiction is given?
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?
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?
Easy way:
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
Code: Select all
timeWaited = 0
timeToWait = 10
function love.update(dt)
timeWaited = timeWaited + 1
if timeWaited >= timeToWait then
--do something here
end
end
that way you can get to know when a certain event happens.
In that case you wanna do something after 10 seconds
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: How do i wait until a certain condiction is given?
That will do something after 10 frames, and then once every frame.xNick1 wrote:Easy way:
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
Help us help you: attach a .love.
Who is online
Users browsing this forum: Google [Bot] and 3 guests