我一直在为我制作一个海龟矿的程序。这里是:
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)
我看了看,声明有一个“结束”。但是,如果我注释掉返回函数,它就可以工作。