我一直在为我做一个乌龟矿的程序。在这里:
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("-------Mining Operation Alpha-------")
term.setCursorPos(1,2)
term.write("Commence Mining Operation? (y/n): ")
local input = read()
if input == "n" then
term.setCursorPos(1,3)
print("Cancelling Operation")
sleep(1)
exit()
elseif input == "y" then
term.setCursorPos(1,3)
print("Commencing Alpha Mine")
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' expected (to close 'if' at line 12)
我查看了一下,该陈述有一个“结尾”。但是,如果我注释掉返回函数,它将起作用。如果有人知道解决方案或漏洞来完成这项工作,我将不胜感激。预先感谢!
答案 0 :(得分:2)
return语句必须是块中的最后一条语句。
您可能想要
function up()
fuel()
if turtle.up() then
depth = depth - 1
return true
else
return false
end
end