Lua循环与错误检测未能正确工作。
2015-2-5 16:48:2
收藏:0
阅读:87
评论:1
我几周前编写了一个简单的机器人程序,并在我不断扩大理解的新知识基础上不断完善它。
local B = 1 --Boss check 1 = true, 2 = false
repeat
function bossCheck()
local rgb1 = getColor(x,y)
if rgb1 == (rgb) then
touchDown(x,y)
usleep(time)
touchUp(x,y)
end
local D = 1 --Delay, corrective action when script is out of sync with loading times
repeat
if rgb1 ~= (rgb) then
D = D + 1
usleep(time)
end
until D == 5
end
if D == 5 then
B = B + 1
end
until B == 2
if B == 2 then
alert("No Boss")
end
这实际上可以循环执行,直到我添加了纠正检查延迟。如果 function bossCheck() 失败,那么在我的想法中它应该 repeat。我以为这个是可行的,或者我错把代码块的位置了?
在我加入 local D = 1 --for delay 的代码之前,我会尝试在我的 iOS 屏幕上触摸两次,它会返回 not true 的结果,然后我的循环就结束了。但是现在,我运行我的脚本,什么都不会发生,而且似乎脚本无限运行。
这非常令人困惑。我不指望在这里得到逐字逐句的代码,但是请指引我朝正确的方向努力。
编辑 - 示例
function bossCheck ()
if (getColor(x,y) == "color1") then
return true;
end
return false;
end
function onBoss ()
touch(x,y)
usleep(time)
return true;
end
function fightBoss ()
touch(x2,y2)
usleep(time)
return true;
end
function bossReturn ()
touch (x3,y3)
usleep(time)
return true;
end
function bossLoop ()
while (bossCheck) do
onBoss ();
fightBoss ();
bossReturn ();
end
end
repeat
bossLoop ();
until (bossCheck == false)
if (bossCheck == false) then
alert("Boss Loop End")
end
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
好的,
repeat until会执行给定的脚本,直到执行到某个语句。你的脚本重新定义了
bossCheck函数,并检查D是否等于5(D为空)。你没有在任何地方调用
bossCheck,所以B仍然为1。这个脚本应该工作。
local noBoss = false; function bossCheck() noBoss = false; local rgb1 = getColor(x,y); if (rgb1 == rgb) then touchDown(x,y) usleep(time) touchUp(x,y) return -- 如果为真,停止该函数的执行; end noBoss = true; usleep(time * 5); -- 调用时没有意义将应用程序操作延迟5倍,当我们调用只需将睡眠量乘以5; end repeat bossCheck(); until noBoss; if (noBoss) then alert("No Boss"); end编辑:
我将演示如何按顺序调用几个函数的示例
function bossCheck() if (getColor(x,y) == rgb) -- 而不是 rgb1=.. touchDown(x,y) usleep(time) touchUp(x,y) return true; end return false; end while true do if (not bossCheck()) then alert("No Boss"); break; -- 退出循环 end if ((function () return true)()) then alert("This local function return true.. so alert message is shown\nYou can do the same with any other functions"); end end根据你的示例,你可以这样做
function bossCheck() if (getColor(x,y) == rgb) -- 而不是 rgb1=.. return true; end return false; end while true do if (bossCheck()) then touch(x,y) usleep(time) touch(x2,y2) usleep(time) touch(x3,y3) usleep(time) else alert("No Boss"); break; -- 退出循环 end end