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

[Question] my turtles can't deal with grave

Started by f9_2, 26 February 2013 - 01:02 PM
f9_2 #1
Posted 26 February 2013 - 02:02 PM
[Question] my turtles can't deal with gravel

Well i'm trying to write a program for turtles to mine 3 tall 1 wide shafts with 2 blocks in between them, which i can input the lenght(right now i have preset it to 50) and the way it works is it checks for blocks then digs them if there are any then moves(checks up, down and front and mines in that order) then when its done it comes all the way back to where it started but when there is gravel in the way it dig one less row for each row of gravel it comes across and then it goes back to far, i've tried what i could to fix this but i can't get the turtle to dig the shaft and come back properly i would like to hear suggestions on what i could do to fix this, here is the code i wrote:


--input screen
shell.run('clear')
print("------------------------------")
print("How far do you want me to dig?")
print("------------------------------")
--variables, the 50 is temporary
local x = 50 --io.read()
local i = 0
--functions
local function checkfuel()
  if turtle.getFuelLevel() < 5 then
    turtle.select(1)
    turtle.refuel(1)
    turtle.select(1)
  end
end

local function minerow()
  for i=0,x do
    print("Shaft is "..tostring(i).." blocks long.")
    while turtle.detectUp() == true do
	  turtle.digUp()
    end
    if turtle.detectDown() == true then
	  turtle.digDown()
    end
    while turtle.detect() == true do
	  turtle.dig()
    end
    if turtle.detect() == false then
	  turtle.forward()
    else
	  while turtle.detect() == true do
	    turtle.dig()
	  end
	  turtle.forward()
    end
  end
end
local function comeback()
  turtle.turnRight()
  turtle.turnRight()
  for i=0,x do
    while turtle.detect() == true do
	  turtle.dig()
    end
    if turtle.detect() == false then
	  turtle.forward()
    else
	  while turtle.detect() == true do
	    turtle.dig()
	  end
	  turtle.forward()
    end
  end
end
local function nextpos()
  turtle.turnRight()
  checkfuel()
  turtle.forward()
  turtle.forward()
  turtle.forward()
  turtle.turnRight()
end
minerow()
comeback()
nextpos()
The_Awe35 #2
Posted 26 February 2013 - 03:59 PM
It is actually really easy to stop gravel all you have to do is this:


for i = 1,x do
  while not turtle.forward() do
  turtle.dig()
  end
end

This makes the turtle try to go forward as well, so if it is able to go forward, it will move. Very simple code and no more problems with gravel!
You will have to adapt your code a bit to make it work with this, but it will work. It won't work with gravel above your turtle, so it may fall ontop of the turtle, and when it moves, fall onto the ground, just warning you.
Also, why do you select 1 again after you refuel? it isn't necessary
SuicidalSTDz #3
Posted 26 February 2013 - 06:10 PM
Hehe, Lyqyd or another mod must've "forgotten" to add the "l" in "gravel". Quite ironic actually… (That is assuming this was in the new thread Lyqyd created, otherwise it is f9_2's derp)
f9_2 #4
Posted 27 February 2013 - 06:35 AM
why do you select 1 again after you refuel? it isn't necessary

first, thanks for your help i will try that and thanks again for pointing that out, i forgot a 6 in the first string because i want to have the fuel on the last slot but have the 1 always selected for the part of the code ( which i haven't added yet) that drops the items into pipes/chests because i don't want it to drop the fuel along with the ores so i made it select a different slot then return back to the first one but i forgot a number.

EDIT: it worked perfectly gravel is not a problem anymore working on the deposit code and i'm adding some more lines so i can choose how many shafts i want and how long they can be maybe when its all done and working perfectly i will share it so other can use it as well.