PDA

View Full Version : Delay in Lua?



zuilin
November 8th, 2020, 17:08
Does anyone know if there is a way to implement a visible delay using Lua?

I've tried with os.clock like this but it doesn't delay in execution order, it seems to delay the whole function it's in from executing (even if this is at the end of the function):


local start = os.clock();
while os.clock() - start < 1.0 do end


I suspect it has something to do with how FG threads.

Thoughts?

Moon Wizard
November 8th, 2020, 17:58
There is no function to delay the scripts. Because the UI fires events and interacts with the Lua engine all the time and change the state of objects, it is single threaded (or else lots of assumptions and code would break). So, you can't introduce delays into any Lua code without delaying the whole engine.

The alternate answer is probably some sort of timer support in the Lua coding; but that's not currently on our radar.

Regards,
JPG

zuilin
November 14th, 2020, 04:04
Yeah, os.clock() works but does delay the whole engine. Too bad.

celestian
November 14th, 2020, 06:27
Yeah, os.clock() works but does delay the whole engine. Too bad.

It would be really nice to have a non-blocking timer event system.

SilentRuin
November 14th, 2020, 14:24
Think of it as a single thread going through things you want done - and if you want to keep doing "other things" and come back to this thing your trying to delay - you'd have to constantly have things checking that stored time to see "are we there yet?" periodically throughout your code - and then be able to do whatever it was you delayed whenever that happened. Not pretty. But I know no other way. If you find one make sure you update this thread.