Skip to content

Instantly share code, notes, and snippets.

@johnkraczek
Created March 5, 2023 17:38
Show Gist options
  • Save johnkraczek/20b6b2877cf3fc0ca183e8d56f253e75 to your computer and use it in GitHub Desktop.
Save johnkraczek/20b6b2877cf3fc0ca183e8d56f253e75 to your computer and use it in GitHub Desktop.
turtle location
args = { ... }
X = 0
Y = 0
Z = 0
R = 0
R = tonumber(args[1])
Fx = 1
Fy = 0
function CheckR(msg)
-- print(msg .. ": X:" .. X .. " Y:" .. Y .. " Z:" .. Z .. " R:" .. R)
if (X * X + Y * Y + Z * Z > R * R) then
return true;
end
return false;
end
function MoveForward()
if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 10 then
turtle.refuel()
end
if turtle.detect() then
turtle.dig()
end
turtle.forward()
X= X + Fx
Y= Y + Fy
end
function TurnRight()
if (Fx==1 and Fy==0) then
Fx = 0
Fy = 1
end
if (Fx==0 and Fy==1) then
Fx = -1
Fy = 0
end
if (Fx==-1 and Fy==0) then
Fx = 0
Fy = -1
end
if (Fx==0 and Fy==-1) then
Fx = 1
Fy = 0
end
turtle.turnRight()
end
function TurnLeft()
if (Fx==1 and Fy==0) then
Fx = 0
Fy = -1
end
if (Fx==0 and Fy==-1) then
Fx = -1
Fy = 0
end
if (Fx==-1 and Fy==0) then
Fx = 0
Fy = 1
end
if (Fx==0 and Fy==1) then
Fx = 1
Fy = 0
end
end
while CheckR('fwd') do
MoveForward()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment