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

Help with Gravel Handling

Started by firekicker8, 05 August 2013 - 10:01 PM
firekicker8 #1
Posted 06 August 2013 - 12:01 AM
I have created a tunneling program that digs a specific number of 3x3 panels in one direction. I would like to know how i can make the turtle work with gravel and other things (aka lava, water, etc.). I am NOT looking for someone to post a link to an already completed tunnel bore program, i am looking to improve my coding and this is personal practice. Thanks!

Here is the code: http://paste.ubuntu.com/5953733/
Lyqyd #2
Posted 06 August 2013 - 12:25 AM
Split into new topic.

The basic idea behind gravel handling is to see whether an attempt to go forward fails or succeeds, and attempting additional digs or attacks as necessary until it does succeed.
firekicker8 #3
Posted 06 August 2013 - 01:16 AM
how can i detect a fail or success?
immibis #4
Posted 06 August 2013 - 03:48 AM
All turtle movement functions return true if they succeed, or false if they fail.
Zeph #5
Posted 06 August 2013 - 10:09 AM
instead of having a list of commands (because if one fails, it skips it and moves on, yet is now in the wrong position) you should have a "try to move forward".

for example
function moveForward()
  if not turtle.forward() then -- First thing first, try to move forward
 
    repeat -- If you cannot move forward, find out why, act upon it, then try again
	  
	  -- is there a block infront?
	  if turtle.detect() then
	    turtle.dig() -- dig it out!
	    
	  -- is there a mob infront?
	  elseif turtle.attack() then
	    repeat -- Keep attacking it!
		  sleep(1)
	    until not turtle.attack()
	    
	  -- Are you out of fuel?
	  elseif turtle.getFuelLevel < 1 then
	    for slot = 1,16 -- Scan all slots for fuel
		  turtle.select(slot)
		  turtle.refuel(1)
		  if turtle.getFuelLevel > 0 then -- if we have fuel, stop scanning
		    break
		  end
	    end
	  end
	  
	  sleep(0.5) -- small pause before next try (see below)
	  
	  until turtle.forward() -- stop if you move forward, finally
  end
end
firekicker8 #6
Posted 18 August 2013 - 01:51 AM
thank you so much, after reading that it just kinda hit me…. derp. XD