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

Seriously Simple Strip Mine (Mining Turtle)

Started by Vralka, 19 April 2013 - 07:05 AM
Vralka #1
Posted 19 April 2013 - 09:05 AM
Are you trying to set up a server? Are you trying to make long strip mines without the hassle of digging them yourself?
Take this program, put it into a turtle and just start the program up!
The turtle takes torches in slot 1, and chests in slot 2. Once it runs out of torches, chests or has only enough fuel to return, it will return to where it started ,face the tunnel and tell you why it stopped!

Special features:
  • Has a very simple EnderChest capability. Simply set 'enderchest' to true, and it works!
  • Easy to set up for different light sources, simply edit the 'light' function for floor lighting, or edit the first for loop in the main while loop to make more space between the torches if you're using better torches!
  • Tells you why the tunneling stopped.
Using this system will allow you to dig a two block tall strip mine, allowing you to access all of the ores there. Set up a few of these three blocks apart, and just check the walls once they're done!

By Default:
  • Torch spacing is set to 12, prevents mob spawning with regular torches
  • Enderchest is turned off.
  • The turtle has no refueling capability, refuel before the strip to control the journey length.
The code:
Spoilerlocal enderchest = false
local torch = turtle.getItemCount(1)
local chests = turtle.getItemCount(2)
local dist = 0

function dump()
if turtle.getItemCount(16)>0 then
turtle.digDown()
turtle.select(2)
turtle.placeDown()
for slot = 3,16,1 do
turtle.select(slot)
turtle.dropDown()
end
if enderchest then
turtle.select(2)
turtle.digDown()
else
c = c - 1
end
end
end

function digforw()
if turtle.detect() then
turtle.dig()
end
turtle.forward()
dump()
turtle.digUp()
dump()
dist = dist + 1
end

function home()
turtle.turnLeft()
turtle.turnLeft()
if turtle.detectUp() then
turtle.digUp()
end
turtle.up()
for i=1,dist,1 do
turtle.forward()
end
turtle.down()
if torch==0 then
print("Ran out of torches.")
elseif chests==0 then
print("Ran out of chests.")
else
print("Ran out of fuel.")
end
turtle.turnLeft()
turtle.turnLeft()
end

function light()
turtle.turnLeft()
turtle.turnLeft()
turtle.select(1)
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
torch = torch - 1
end

local retdist = 0
local fuel = turtle.getFuelLevel()
function run()
while (torch>0) and (chests>0) and (fuel>retdist) do
for i=1,12,1 do
digforw()
end
light()
retdist = dist + 14
fuel = turtle.getFuelLevel()
end
home()
end

run()

Or get it on your turtles with pastebin code:
pastebin get vMSPVVi0
or just go and see it at http://pastebin.com/vMSPVVi0

Hope you like this!
- Vralka
terrapinlogo #2
Posted 23 April 2013 - 10:41 PM
Hey, would you mind if I post a modified version of this code up? Full credit etc. to you for the original code. I stripped it down to a tunnel miner and then changed the size of the tunnel to 3x2 and extended it so that it makes multiple tunnels with a two block wall between them.

Terra
Cheesety210 #3
Posted 11 July 2013 - 04:14 PM
tunnel2:19: attemp to perform arithmetic __sub on nil and number

Erorr.

I fixed it here : pastebin.com/bk8xaz9N

The problem was, you can't do c = c - 1.
You have to do : local c = c - 1
johnneijzen #4
Posted 16 September 2013 - 11:39 AM
There my Turtle Program it Just like this program but my is working http://www.computercraft.info/forums2/index.php?/topic/15292-john-strip-mining-turtle/
jag #5
Posted 16 September 2013 - 01:23 PM
You could do

c = (c or 0) - 1
where you could replace 0 with the default, I presume 0 would be the starting point.
kreezxil #6
Posted 16 September 2013 - 03:26 PM
You could do

c = (c or 0) - 1
where you could replace 0 with the default, I presume 0 would be the starting point.

Is this a joke? Why all the emphasis on that line? I don't see where c is being used anywhere. Looks like the programmer didn't want that else block to me.
johnneijzen #7
Posted 17 September 2013 - 04:30 AM
You could do

c = (c or 0) - 1
where you could replace 0 with the default, I presume 0 would be the starting point.

Is this a joke? Why all the emphasis on that line? I don't see where c is being used anywhere. Looks like the programmer didn't want that else block to me.

That is why i remove it Because has no use. http://pastebin.com/ZRak7N4X (Still lot Fixing To Do)
jag #8
Posted 17 September 2013 - 05:11 AM
Is this a joke? Why all the emphasis on that line? I don't see where c is being used anywhere. Looks like the programmer didn't want that else block to me.
Lol I am sorry, I can stay quiet
turtle5204 #9
Posted 17 September 2013 - 07:23 PM
Epic program! Use cheese's fix and you have no errors!
turtle5204 #10
Posted 18 September 2013 - 06:17 AM
Found an error. It stops when it places a chest.
johnneijzen #11
Posted 18 September 2013 - 11:21 AM
Epic program! Use cheese's fix and you have no errors!

I had Error with cheese fix when you watch turtle it will place down chest put item in it then break it aging and place chest and all items lands on floor
sammystriano #12
Posted 28 December 2015 - 07:27 PM
I have found the solution! the problem was that c should be chests not c so replace c = c - 1 to chests = chests - 1

I have found the solution! the problem was that c should be chests not c so replace c = c - 1 to chests = chests - 1
Right after "turtle.Dropdown()" on the next line down put "turtle.select(3)" that will solve the multiple chests