This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
unlimited's profile picture

Udig - Mining Turtle

Started by unlimited, 04 September 2012 - 01:50 PM
unlimited #1
Posted 04 September 2012 - 03:50 PM
Hi,

I've been trying to find a good quarry program for a while and yesterday i gave up and made one myself.

You can change the width, length and height.

pastebin:
Spoilerhttp://pastebin.com/G0aRHRru
code:
Spoiler– change mx for width, my for length and mz for height, the turtle will dig down and to the right
mx = 50
my = 50
mz = 10
– Don't change anything bellow this line

x = 0
y = 0
z = 0
cx = 0
cy = 0
cz = 0

posy = 0
posx = 0

function f()
if turtle.forward() == false then
repeat
turtle.dig()
sleep(0.25)
until turtle.forward() == true
end
end

function d()
if turtle.down() == false then
repeat
turtle.digDown()
sleep(0.25)
until turtle.down() == true
end
end

function u()
if turtle.up() == false then
repeat
turtle.digUp()
sleep(0.25)
until turtle.up() == true
end
end

function check()
for i = 1,8 do
if turtle.getItemCount(i) == 0 then
return true
end
end
end

function dropall()
for dropSlot = 1,9 do
turtle.select(dropSlot)
turtle.drop()
end
turtle.select(1)
turtle.turnRight()
turtle.turnRight()
end

function down()
while cz < mz do
d()
cz = cz+1
end
end

function up()
while cz > z do
u()
cz = cz-1
end
end

function bdig()
if cz == z and cx == x then
goback()
dropall()
else
up()
goback()
dropall()
end
end

function goback()
posy = cy
posx = cx + 1
print("y - ",posy)
print("x - ",posx)
turtle.turnLeft()
while cx > x do
f()
cx = cx - 1
end
turtle.turnLeft()
while cy > y do
f()
cy = cy - 1
end
end

function udig()
while check() and cy < my do
turtle.digUp()
down()
up()
f()
cy = cy+1
end
bdig()
end

while true do
if posx == x then
while cy < posy do
f()
cy = cy + 1
end
udig()
elseif posx < mx and posy == my then
turtle.turnRight()
while cx < posx do
f()
cx = cx + 1
end
turtle.turnLeft()
udig()
elseif posx < mx and posy ~= my then
turtle.turnRight()
while cx < posx - 1 do
f()
cx = cx + 1
end
turtle.turnLeft()
while cy < posy do
f()
cy = cy + 1
end
udig()
elseif posy == my and posx == mx then
print("Complete")
break
end
end

The turtle will dig until area is clear.

When full the turtle will return to start and drop all items on the block behind it, then go back to the spot and keep digging.

I use a transposer behind the turtle connected to a chest and the turtle will drop all items in the chest, i don't have 1.4 yet, so i don't have the fuel option and putting items directly into chests.

I'm not very good at lua, so please feel free to suggest any changes to the code.

enjoy =P


PS: anyone know how to save variables in a file or something so it keeps the coords after reboot?
FrostVolkoff #2
Posted 05 September 2012 - 07:41 PM
Make a GPS tower :D/>/>
dextermb #3
Posted 11 September 2012 - 01:12 PM
-- change mx for width, my for length and mz for height, the turtle will dig down and to the right
mx = 50
my = 50
mz = 10
-- Dont change anything bellow this line

x = 0
y = 0
z = 0
cx = 0
cy = 0
cz = 0

posy = 0
posx = 0

function f()
if turtle.forward() == false then
  repeat
  turtle.dig()
  sleep(0.25)
  until turtle.forward() == true
end
end

function d()
if turtle.down() == false then
  repeat
  turtle.digDown()
  sleep(0.25)
  until turtle.down() == true
end
end

function u()
if turtle.up() == false then
  repeat
  turtle.digUp()
  sleep(0.25)
  until turtle.up() == true
end
end

function check()
for i = 1,8 do
  if turtle.getItemCount(i) == 0 then
   return true
  end
end
end

function dropall()
for dropSlot = 1,9 do
  turtle.select(dropSlot)
  turtle.drop()
end
turtle.select(1)
turtle.turnRight()
turtle.turnRight()
end

function down()
while cz < mz do
  d()
  cz = cz+1
end
end

function up()
while cz > z do
  u()
  cz = cz-1
end
end

function bdig()
if cz == z and cx == x then
  goback()
  dropall()
else
  up()
  goback()
  dropall()
end
end

function goback()
posy = cy
posx = cx + 1
print("y - ",posy)
print("x - ",posx)
turtle.turnLeft()
while cx > x do
  f()
  cx = cx - 1
end
turtle.turnLeft()
while cy > y do
  f()
  cy = cy - 1
end
end

function udig()
while check() and cy < my do
  turtle.digUp()
  down()
  up()
  f()
  cy = cy+1
end
bdig()
end

while true do
if posx == x then
  while cy < posy do
   f()
   cy = cy + 1
  end
  udig()
elseif posx < mx and posy == my then
  turtle.turnRight()
  while cx < posx do
   f()
   cx = cx + 1
  end
  turtle.turnLeft()
  udig()
elseif posx < mx and posy ~= my then
  turtle.turnRight()
  while cx < posx - 1 do
   f()
   cx = cx + 1
  end
  turtle.turnLeft()
  while cy < posy do
   f()
   cy = cy + 1
  end
  udig()
elseif posy == my and posx == mx then
  print("Complete")
  break
end
end
unlimited #4
Posted 11 September 2012 - 03:04 PM
did you change anything?
i actually don't use this anymore i remade it so it could refuel and save pos on files so it doesn't reset on reboot
yyttuuyy #5
Posted 17 September 2012 - 11:12 PM
i tried to get the program (tekkit version) with the http command but I keep geting lua:27: [string "lua"] :1: '<name.' expected
any ideas on what's happening and or how to fix it
RayceFarelle #6
Posted 13 November 2012 - 12:27 AM
Nice and simple program you've made here. Although if there are any improvements you should make, it would be the ability to identify the bedrock. Thanks again for the program and keep up the good work.