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

Most efficient way of dealing with gravel for a mining turtle?

Started by Vogon_Jeltz, 08 January 2013 - 03:37 AM
Vogon_Jeltz #1
Posted 08 January 2013 - 04:37 AM
One of my functions is currently:

-- Digs and moves into a 1x2x1 (xyz) area.
function basicDigAndMove()
  while turtle.detect() do
	turtle.dig()
	sleep(0.5)
  end
  turtle.forward()
  while turtle.detectUp() do
	turtle.digUp()
	sleep(0.5)
  end
end

I was wondering, seeing as I'm moving the turtle forwards after digging the block in front of it, would it be more efficient to use while not turtle.forward do instead of while turtle.detect() do?

And if I changed it to while not turtle.forward do, could I get rid of the sleep(0.5) after the digUp()? As when it's detecting the block in front the sleep is necessary because of the fall time of gravel/sand, but surely I could remove the sleep because the turtle not being able to move forward is the same as detecting a block in front (in this case)?
Goof #2
Posted 08 January 2013 - 04:58 AM
You can use a while not turtle.forward do …
And yes,
You can take the sleep "away",
but i always use sleep(0)
so my program does not return the error :
"too long Without yielding"
but its up to you.
i Hope i could help :D/>
Vogon_Jeltz #3
Posted 08 January 2013 - 05:24 AM
You can use a while not turtle.forward do …
And yes,
You can take the sleep "away",
but i always use sleep(0)
so my program does not return the error :
"too long Without yielding"
but its up to you.
i Hope i could help :D/>

Thanks, you did!
Lyqyd #4
Posted 08 January 2013 - 06:23 AM
Also, if you're making calls to turtle.forward, you won't need to keep even a sleep(0) in there, as turtle.forward yields internally as well.
Vogon_Jeltz #5
Posted 08 January 2013 - 01:24 PM
If using while not turtle.forward() do is more efficient (as you don't have to use sleep()), I wonder if it would actually overall work out faster to have a turtle that mined in front of it, moved forward, above it, moved upwards, in front of it, moved forwards, below it and moved downwards.


-- Digs and moves into a 1x2x2 (xyz) area.
function basicDigAndMove()
  while not turtle.forward() do
    turtle.dig()
  end
  while not turtle.up() do
    turtle.digUp()
  end
  while not turtle.forward() do
    turtle.dig()
  end
  while not turtle.down() do
    turtle.digDown()
  end
end

Would this be the most efficient way of mining a 1x2 (xy) tunnel whilst accounting for blocks that are affected by gravity (sand, gravel)? Or does the extra time (& fuel) taken by moving up & down make it not as efficient?
theoriginalbit #6
Posted 08 January 2013 - 01:30 PM
I would probably have the turtle on the top layer and then get it to dig down. far better on fuel


function basicDigAndMove()
  while not turtle.forward() do
	-- may also want to check fuel, as its another cause of not moving
	if not turtle.dig() then
	  turtle.attack()
	end
  end

  turtle.digDown()
end

this would have it try forwards, if it cant, it will dig, if it cant dig it will attack, all until it can move forward, once it moves forward it will dig down. this would dig a 1x2 tunnel. however it could easily be made into a 1x3 by adding this in.


while turtle.detectUp()
  turtle.digUp()
end
Edited on 08 January 2013 - 12:31 PM
Vogon_Jeltz #7
Posted 08 January 2013 - 01:56 PM
Ah. The if not turtle.dig() then turtle.attack() is a nice addition.

Ideally I'd have my turtle on the bottom layer though, because I also have another function that checks if there's a block underneath, and if not, it places one. I also have a function to check the fuel levels.

How is


function basicDigAndMove()
  while not turtle.forward() do
	-- may also want to check fuel, as its another cause of not moving
	if not turtle.dig() then
	  turtle.attack()
	end
  end

  turtle.digDown()
end

better on fuel than this though?


function basicDigAndMove()
  while not turtle.forward() do
	if not turtle.dig() then
	  turtle.attack()
	end
  end
  while turtle.detectUp() do
	turtle.digUp()
    sleep(0.5)
  end
end
theoriginalbit #8
Posted 08 January 2013 - 02:03 PM
Last I checked fuel was only used when moving, not digging. So both of those would consume the same. A lot better than moving it up and down.
Vogon_Jeltz #9
Posted 08 January 2013 - 02:13 PM
Ah okay. Thanks!