7 posts
Location
UK
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)?
767 posts
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/>
7 posts
Location
UK
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!
8543 posts
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.
7 posts
Location
UK
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?
7508 posts
Location
Australia
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
7 posts
Location
UK
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
7508 posts
Location
Australia
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.
7 posts
Location
UK
Posted 08 January 2013 - 02:13 PM
Ah okay. Thanks!