Lua Program Delay

后端 未结 2 732
萌比男神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:07

    The os.clock function returns the number of seconds of CPU time for the program. So the sleep function of yours waits for n seconds, if you need to delay 2 minutes, just call:

    sleep(2*60)
    

    Note that there are some better solutions to implement sleep functions other than busy waiting, see Sleep Function for detail.

提交回复
热议问题