Lua program delay

How can I use this to add a 2 minute delay to my Lua program, here is the code for the delay, but I don't know how to add a delay.

function sleep(n)
  local t = os.clock()
  while os.clock() - t <= n do
    -- nothing
  end
end
+4
source share
1 answer

The function os.clockreturns the number of seconds of processor time for the program. Thus, sleepyour wait function waits for nseconds, if you need to delay 2 minutes, just call:

sleep(2*60)

Please note that there are several better solutions for implementing functions sleepother than expected; see Sleep Function for details.

+4
source

All Articles