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

Diggit - Easy to use Tekkit friendly mining program!

Started by maaatin, 05 August 2012 - 01:14 AM
maaatin #1
Posted 05 August 2012 - 03:14 AM
I've created a simple, quick mining program for mining turtles that works really well! It tells the turtle to dig a 1x1 horizontal shaft until no inventory slots are empty. It then turns around, returns to its starting position and drops everything. It is best to place a transposer/obsidian pipe (if you are using Tekkit) one block in front of the turtle and have everything it drops go straight into a chest. After it drops everything, it turns around and continues to dig for x repetitions. The best thing about this code is that it is relatively short, so it is easy to manually write into a turtle/floppy disk if you are playing on a server that does not allow you to place a program file in the game.

To use this code, create a program with the following code:


function Cycle()
Forward=1
while turtle.getItemCount(1)<1
or turtle.getItemCount(2)<1
or turtle.getItemCount(3)<1
or turtle.getItemCount(4)<1
or turtle.getItemCount(5)<1
or turtle.getItemCount(6)<1
or turtle.getItemCount(7)<1
or turtle.getItemCount(8)<1
or turtle.getItemCount(9)<1 do
turtle.dig()
turtle.forward()
Forward=Forward+1
end
if turtle.getItemCount(1)>=1
and turtle.getItemCount(2)>=1
and turtle.getItemCount(3)>=1
and turtle.getItemCount(4)>=1
and turtle.getItemCount(5)>=1
and turtle.getItemCount(6)>=1
and turtle.getItemCount(7)>=1
and turtle.getItemCount(8)>=1
and turtle.getItemCount(9)>=1
then turtle.turnLeft()
turtle.turnLeft()
end
for i=1,Forward-1 do
turtle.forward()
end
turtle.drop()
turtle.select(2)
turtle.drop()
turtle.select(3)
turtle.drop()
turtle.select(4)
turtle.drop()
turtle.select(5)
turtle.drop()
turtle.select(6)
turtle.drop()
turtle.select(7)
turtle.drop()
turtle.select(8)
turtle.drop()
turtle.select(9)
turtle.drop()
turtle.turnLeft()
turtle.turnLeft()
end
v = io.read()
for j=1,v do
Cycle()
end

Then type the name of the program, press enter, and finally type the number of trips you want your turtle to perform. It will get to work digging for you!

Note: I'm not an experienced coder, if there is any way to condense this code let me know! Thanks! :P/>/>
tele_iz_dva4a #2
Posted 08 August 2012 - 04:08 PM
You can replace the dropping code with smth like this:
for current = 1, 9 do
  turtle.select(current)
  turtle.drop()
end

Besides, use indentation. It is much clearer to read code. Don't ignore it, really.

Edit: also, try to think, how to use this trick to simplify other two large code duplications.
Bruva James #3
Posted 10 August 2012 - 04:21 PM
Hey i get the error

mine1x1:52: bad argument: number expected, got string

Is one of the letters supposed to be replaced with a number for the number of trips?

mine1x1 is what i called the program
Vangard #4
Posted 13 August 2012 - 12:23 AM
I like this program, it's simple but easy to automate. I modified your code a bit to make it slightly more compact, added tele_iz's corrections, though I'm not really a coder so it's far from optimized.

function spaceLeft()
 for i=1,9 do
  if turtle.getItemCount(i)==0 then
   return true
  end
 end
 return false
end
function Cycle()
 Forward=1
 while spaceLeft() do
  turtle.dig()
  turtle.forward()
  Forward=Forward+1
 end
 if spaceLeft()==false then
  turtle.turnLeft()
  turtle.turnLeft()
 end
 for i=1,Forward-1 do
  turtle.forward()
 end
 for dropSlot = 1, 9 do
	turtle.select(dropSlot)
	turtle.drop()
 end
 turtle.turnLeft()
 turtle.turnLeft()
end
Cycle()
JJRcop #5
Posted 18 August 2012 - 04:54 AM
It's great that you're into computercraft and coding! But, I have bad news.
If you use the command "excavate 1", it does exactly what you coded.
Not that yours is insignificant or bad, it's great you're making stuff! But, this is pre-programmed into ComputerCraft.
Groovehh #6
Posted 18 August 2012 - 07:15 AM
I like this program, it's simple but easy to automate. I modified your code a bit to make it slightly more compact, added tele_iz's corrections, though I'm not really a coder so it's far from optimized.

function spaceLeft()
for i=1,9 do
  if turtle.getItemCount(i)==0 then
   return true
  end
end
return false
end
function Cycle()
Forward=1
while spaceLeft() do
  turtle.dig()
  turtle.forward()
  Forward=Forward+1
end
if spaceLeft()==false then
  turtle.turnLeft()
  turtle.turnLeft()
end
for i=1,Forward-1 do
  turtle.forward()
end
for dropSlot = 1, 9 do
	turtle.select(dropSlot)
	turtle.drop()
end
turtle.turnLeft()
turtle.turnLeft()
end
Cycle()

How would you go about getting this program to repeat itself. As of now it just stops after it drops off the items.
madmatthew14 #7
Posted 11 September 2012 - 06:11 PM
dont know lua code for it but pascal code would be repeat [ALLCODEINHERE] until X,Y,Z = max values
ttouch #8
Posted 04 January 2013 - 12:40 PM
to repeat forever:

while true do
Cycle()
end