Wait function in lua

Hello everyone!

I make a game and I realized that I need the wait() function. And I found this:

function wait(t)
 	local start = os.time()
 	repeat until os.time() > start + t
end

But that function freezing my program. I don’t know why.
Please, help me.

What’s freezing it is that while you’re waiting the engine will not continue to render more frames and execute other scripts. You need to do something else, what that something else is depends on why you want to wait.

You could use a API reference (timer) to delay the execution of a function. If you need to wait for something to complete then using coroutines is probably want you want to do, I usually use flow.lua to simplify such things.

9 Likes