Lua Program Delay

后端 未结 2 702
萌比男神i
萌比男神i 2021-01-13 02:15

How would I use this to add a delay of 2 minutes to my Lua program, here is the code for the delay, but I dont know how to add the delay.

function sleep(n)
          


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-13 03:04

    Maybe this will work

        function sleep(n)
             n = math.ceil(n)
             if n <= 0 and n > 99999 then return end --If the user enter a number below 0 and higher than 99999 the limit in TIMEOUT command in Windows
             os.execute("timeout /T "..tostring(seconds).." /NOBREAK")
        end
    

    This will not wasting CPU time by busy loop but "Waiting for n seconds, press CTRL+C to quit ..." In Windows you can use -1 but it will wait forever so i restrict it because waiting forever is useless. And if you don't want "Waiting for n seconds, press CTRL+C to quit ..." to appear i don't know for that can do same thing without display that. If you want get rid of that just add os.execute("cls") after the os.execute("timeout /T "..tostring(seconds).." /NOBREAK") statement and it will clear up the console

提交回复
热议问题