Easiest way to make lua script wait/pause/sleep/block for a few seconds?

前端 未结 19 1423
礼貌的吻别
礼貌的吻别 2020-12-03 00:41

I cant figure out how to get lua to do any common timing tricks, such as

  • sleep - stop all action on thread

  • pause/wait - don\'t go on to the

19条回答
  •  青春惊慌失措
    2020-12-03 01:18

    cy = function()
        local T = os.time()
            coroutine.yield(coroutine.resume(coroutine.create(function()
        end)))
        return os.time()-T
    end
    sleep = function(time)
        if not time or time == 0 then 
            time = cy()
        end
        local t = 0
        repeat
            local T = os.time()
            coroutine.yield(coroutine.resume(coroutine.create(function() end)))
            t = t + (os.time()-T)
        until t >= time
    end
    

提交回复
热议问题