搜索
查看: 743|回复: 1

LUA定时器如何写和如何执行?

[复制链接]
发表于 2021-6-27 12:02:01 | 显示全部楼层 |阅读模式
引擎有例子,但是不会用啊!
这是引擎的例子:
local _timerID = 0local function ontimer(dt)-- dt=上下文参数表        dt.process = dt.process + 1                        if (dt.process > 60) then                print("时钟执行了60次")                c.timer.del(_timerID) --删除时钟                return        end        print("当前次数:"..dt.process)end_timerID = c.timer.add(1000, 0, ontimer, {process = 0})

假如我要设置人物等级达到60级后提示文字,持续5秒,每秒提示1次:if DJ == [url=mkMSITStore:C:\Users\Administrator\Desktop\HGE210219\HGE%E5%BC%95%E6%93%8EM2%E8%AF%B4%E6%98%8E%E4%B9%A6.chm::/lua%E8%84%9A%E6%9C%AC%E6%8E%A5%E5%8F%A3/%E6%9C%8D%E5%8A%A1%E7%AB%AF/%E5%AF%B9%E8%B1%A1/actor%E5%AF%B9%E5%83%8F.html#getLevel]actor:getLevel[/url]() thenplay:sendCenterMsg(0,254,"您已60级!",0, 10, 3)以上条件与执行如何代入到上面定时器中??


补充内容 (2021-6-27 12:03):
崩了,看二楼
 楼主| 发表于 2021-6-27 12:02:25 | 显示全部楼层
引擎有例子,但是不会用啊!
这是引擎的例子:
local _timerID = 0

local function ontimer(dt)-- dt=上下文参数表
        dt.process = dt.process + 1               
        if (dt.process > 60) then
                print("时钟执行了60次")
                c.timer.del(_timerID) --删除时钟
                return
        end
        print("当前次数:"..dt.process)
end

_timerID = c.timer.add(1000, 0, ontimer, {process = 0})


假如我要设置人物等级达到60级后提示文字,持续5秒,每秒提示1次:
if DJ == actor:getLevel() then
play:sendCenterMsg(0,254,"您已60级!",0, 10, 3)

以上条件与执行如何代入到上面定时器中??


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|HGEM2论坛

GMT+8, 2024-9-21 13:46 , Processed in 0.497819 second(s), 14 queries .

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表