以下代码以您希望的方式遍历一个字段。它虽然简单,但是可以工作,但是可以从某种抽象中受益,以使其可用于其他目的。
local rowSize = 7
local colSize = 7
local turnLeft = true
local skipMove = false
function goHome()
local r,c
turtle.turnLeft()
turtle.turnLeft()
for c=1,colSize-1 do
turtle.forward()
end
turtle.turnLeft()
for r=1,rowSize-1 do
turtle.forward()
end
turtle.turnLeft()
turtle.back()
function harvestRow()
local c
for c=1,colSize do
if skipMove == true then
skipMove = false
else
turtle.forward()
end
turtle.digDown()
end
end
--
-- Move and orient turtle onto next row
--
function nextRow()
if turnLeft == true then
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
turnLeft = false
else
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turnLeft = true
end
skipMove = true
end
--
-- Call to start farming
--
function harvestField()
local r
for r=1,rowSize do
harvestRow()
-- go to next row unless its the last
if r~=colSize then
nextRow()
end
end
goHome()
end
衷心祝愿您的耕作工作一切顺利,并感谢您有机会利用一些旧的Turtle API知识。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句