You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
miner/navigator.lua

39 lines
862 B

local robot = require("robot")
-- Moves forward n blocks.
-- Waits if there is an obstruction
local function forward(n)
for _ = 1, n do
while true do
local result, error = robot.forward()
if result then
break
else
print("Cannot move: " .. error)
end
end
end
end
-- Move until it runs into a solid block.
-- Waits if there is an entity obstrucion
-- Returns number of blocks moved.
local function forward_until_solid()
local moved = 0
while true do
local result, error = robot.forward()
if result then
moved = moved + 1
else
if error == "solid" then
return moved
end
end
end
end
return {
forward = forward,
forward_until_solid = forward_until_solid,
}