矿龟程序中的错误:缺少 'end'(应在第12行关闭 'if')
2020-1-28 22:49:9
收藏:0
阅读:106
评论:1
我一直在开发一个矿龟程序来掘矿。下面是代码:
local depth = 0
local isJunk = true
function fuel()
if turtle.getFuelLevel() < 20 then
turtle.select(16)
turtle.refuel(1)
end
end
function up()
fuel()
if turtle.up() then
return true
depth = depth - 1
else
return false
end
end
function down()
fuel()
if turtle.down() then
return true
depth = depth + 1
else
return false
end
end
function checkWalls()
for i = 1,4 do
for j = 1,6 do
turtle.select(i)
if turtle.compare() then
isJunk = true
end
end
if isJunk == false then
turtle.dig()
end
turtle.turnLeft()
end
end
function digDown()
for k = 1,6 do
turtle.select(k)
if turtle.compareDown() then
if turtle.digDown() then
return true
else
return false
end
end
end
turtle.select(1)
turtle.digDown()
end
function digUp()
for l = 1,6 do
turtle.select(l)
if turtle.compareUp() then
if turtle.digUp() then
return true
else
return false
end
end
end
turtle.select(1)
turtle.digUp()
end
while true do
term.clear()
term.setCursorPos(1,1)
print("-------采矿操作Alpha-------")
term.setCursorPos(1,2)
term.write("开始采矿操作?(y/n): ")
local input = read()
if input == "n" then
term.setCursorPos(1,3)
print("取消操作")
sleep(1)
exit()
elseif input == "y" then
term.setCursorPos(1,3)
print("开始Alpha采矿")
sleep(1)
end
digDn()
down()
digDn()
down()
turtle.select(7)
turtle.placeUp()
checkWalls()
digDn()
while down() do
checkWalls()
digDn()
end
up()
turtle.select(15)
turtle.placeDown()
for m = 1,5 do
up()
end
turtle.dig()
fuel()
turtle.forward()
turtle.dig()
fuel()
turtle.forward()
turtle.turnRight()
turtle.dig()
fuel()
turtle.forward()
turtle.turnLeft()
digDn()
while down() do
digdn()
end
checkWalls()
up()
turtle.select(15)
turtle.placeDown()
checkWalls()
while depth > 1 do
digUp()
up()
checkWalls()
end
digUp()
up()
up()
turtle.select(7)
turtle.placeDown()
fuel()
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
end
1至6个槽位是我不想要挖出的物品,第7个是圆石,第15个是火把,以防止怪物在矿洞底部生成,第16个是煤炭。
每当我运行它时,我都会收到一个错误,说:
bios.lua:26: [string "mine.lua"]:14:缺少 'end'(应在第12行关闭 'if')
我检查了一下,该语句中有 'end'。但是,如果我注释掉返回函数,它就可以运行。
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的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 代码?

一个返回语句必须是块中的最后一条语句。
你可能需要:
function up() fuel() if turtle.up() then depth = depth - 1 return true else return false end end