I've tried
timer.script(function(wait)
repeat
wait(0)
until condiction
end)
but it didn't work. Please help me!
I've tried
timer.script(function(wait)
repeat
wait(0)
until condiction
end)
but it didn't work. Please help me!
timer.script is not really designed for what you're trying to do, though it might be possible to get it to work.
The LÖVE framework is built around the draw()
and update()
callbacks and I would recommend learning how to do this task with just these callbacks, before moving on to methods that layer on top of these callbacks. Something like this should run your code only once, when your condition is first met:
local hasHappened = false
function love.update(dt)
if (condition and not hasHappened) then
hasHappened = true
-- respond to condition here
end
end
Typically, you wouldn't check your condition directly in love.update()
. Instead, you would have a table that contains all the objects in your game, and in love.update()
you loop through this table of objects and call an update()
method on each one. That gives each object a chance to check for different conditions and respond to them.
An alternative approach would be to name your condition and to use an event system like beholder to trigger the event (and any callback functions that are registered) when the condition happens.
Or (provided your timer's update() is being called in love.update()
), you could do it with your timer object and the every()
method:
local handle = timer:every(0.01, function()
if condition then
-- unregister timer, assuming you only want the code to be run once
timer:cancel(handle)
-- respond to condition here
end
end)