zoukankan      html  css  js  c++  java
  • GPRS(Air202) Lua开发: 定时器

    1.延时

    sys.wait(5000) --延时5S

    延时函数一般配合任务使用

    --启动任务
    sys.taskInit(
    function()
            while true do
                log.info("test sys.wait")
                sys.wait(1000) --延时1S
            end
        end
    )

    2.一次性定时器

    function OneTimer(param)
        print(param);
    end
    
    --一次性定时器: sys.timerStart
    --OneTimer:回调函数
    --5000:延时5S
    --最后一个参数:传给回调函数的参数
    sys.timerStart(OneTimer,5000,"这是一个参数")

    3.循环定时器

    local cnt = 0;
    function LoopTimer(param)
        print(param)
        cnt = cnt+1
        if(cnt>=6) then
            cnt = 0;
            sys.timerStop(timerLoop) --停止循环定时器
            print("停止循环定时器")
        end
    end
    
    --一次性定时器: sys.timerStart
    --OneTimer:回调函数
    --1000:延时1S
    --最后一个参数:传给回调函数的参数
    --timerLoop:返回的参数用于关闭定时器
    timerLoop = sys.timerLoopStart(LoopTimer,1000,"这是循环定时器")

     

    4.补充(关闭定时器的第二种方式)

    --sys.timerStopAll(LoopTimer) --LoopTimer:关闭与此回调函数绑定的所有定时器

     

  • 相关阅读:
    【[AH2017/HNOI2017]礼物】
    【[ZJOI2014]力】
    FFT抄袭笔记
    【[SCOI2015]小凸玩矩阵】
    【[SDOI2017]新生舞会】
    bzoj 3277: 串
    【[ZJOI2015]诸神眷顾的幻想乡】
    【[TJOI2017]DNA】
    【[TJOI2018]碱基序列】
    【[TJOI2018]异或】
  • 原文地址:https://www.cnblogs.com/yangfengwu/p/12955709.html
Copyright © 2011-2022 走看看