ComputerCraft 挖掘龟不停止向下挖

我有一个挖掘龟的代码问题。 这是我的代码

function mine ()
    done = false

    while not done do
        print("移动到所需的起始高度...")

        while not (TURTLE_POSITION.y == heightToStart) do
            turtle.digDown()
            turtle.down()
        end

        print("已到达起始高度。过滤物品...")

        filterItems()

        print("过滤物品完成。开始挖掘立方体...")

        done = true
    end
end

问题是,无论如何,龟都会不断地向下挖掘。直到它到达基岩层才停止。

编辑:TURTLE_POSITION代码

function locateTurtle ()
    print("尝试获取位置")
    location = vector.new(gps.locate(5))

    if not location.x then
        print("无法获取位置")
        error()
    end

    print("找到位置")

    return location
end

refuelTurtle(calculateFuelUsage(cuboidX, cuboidY, cuboidZ))

local TURTLE_POSITION = locateTurtle()

点赞
用户12277653
用户12277653

根据我收到的评论,问题很简单:我忘记更新海龟的位置变量

我的代码现在:

function mine()
    done = false

    while not done do
        print("移动到所需的起始高度...")

        while not (TURTLE_POSITION.y == heightToStart) do
            turtle.digDown()
            turtle.down()
            TURTLE_POSITION = locateTurtle()
        end

        print("到达起始高度。筛选物品...")

        filterItems()

        print("筛选物品。开始挖掘长方体...")

        done = true
    end
end

function locateTurtle()
    print("尝试获取位置")
    location = vector.new(gps.locate(5))

    if not location.x then
        print("无法获取位置")
        error()
    end

    print("找到位置")

    return location
end
2020-12-08 22:14:13