Skip to main content

Less Blocking Sleep/Pause

The Lua IDE ui.Sleep command internally calls Thread.Sleep which will freeze the thread that Lua is running in. As a result, a "Stop" cannot be performed on the Lua engine until after that sleep completes. If you're sleeping for a longer period of time this is highly undesirable. An alternative approach is to break the sleep into smaller sleep calls. Using this technique the UI's stop button is able halt the script before the end of the 60 second pause.

-- Sleep for 1 minute before repeating, a "Stop" command can then process
-- after every second.
for i = 1, 60 do
    ui.Sleep(1000)
end
Last Modified: 07/02/2023