18 posts
Posted 13 January 2013 - 01:20 PM
I have made a simple quarrying program. you can edit the hight, width and depth by actually editing the program. Everything works fine if I use it in an area without gravel. The problem is when there is gravel more than one block high that can fall down.
length = 20
l = 0
width = 20
w = 0
depth = 40
d = 0
R = 1
i = 0
function checkfuel()
if turtle.getFuelLevel() < 10 then
turtle.select(16)
turtle.refuel(1)
turtle.select(1)
end
end
function layer()
for w = 1, width do
for m = 1, length do
checkfuel()
turtle.dig()
turtle.forward()
end
if w == width then
checkfuel()
turtle.turnLeft()
turtle.turnLeft()
else
if R == 1 then
R = 0
checkfuel()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
else
R = 1
checkfuel()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
end
end
end
end
for d = 1, depth do
checkfuel()
layer()
turtle.digDown()
turtle.down()
end
I have tried a couple of different methods of dealing with gravel. They seem to work when i'm just testing it out, but with the quarry, it needs to move forward only a certain amount of blocks. The gravel is messing with the count. Both of the ones below don't work. Any help will be appreciated.
function gravel()
if not turtle.forward() then
repeat
turtle.dig()
sleep(0.2)
until turtle.forward()
end
end
function gravel()
if not turtle.forward() then
repeat
turtle.dig()
sleep(0.2)
until turtle.forward()
turtle.back()
end
end
2088 posts
Location
South Africa
Posted 13 January 2013 - 01:26 PM
Just change all 'turtle.forward()' s with
while not turtle.forward() do
turtle.dig()
sleep(0.4) -- needs to sleep for 0.4 because that's the time the block takes to fall or something.
end
7508 posts
Location
Australia
Posted 13 January 2013 - 01:27 PM
while not turtle.forward() do
turtle.dig()
sleep( 0.4 )
end
OFF TOPIC: could also add following check if running CC1.4, as mobs can stop movement too
if not turtle.dig() then
turtle.attack()
end
18 posts
Posted 13 January 2013 - 01:38 PM
while not turtle.forward() do
turtle.dig()
sleep( 0.4 )
end
Using this, would I replace the turtle.forward()'s like remiX said or would I put it before?
2088 posts
Location
South Africa
Posted 13 January 2013 - 01:42 PM
while not turtle.forward() do
turtle.dig()
sleep( 0.4 )
end
Using this, would I replace the turtle.forward()'s like remiX said or would I put it before?
It's the same code.
But also add what he said about attacking the mobs if you're using CC1.4
7508 posts
Location
Australia
Posted 13 January 2013 - 01:43 PM
It's the same code.
Yeh I didn't get that "See 1 new post" thing…
18 posts
Posted 13 January 2013 - 01:49 PM
But also add what he said about attacking the mobs if you're using CC1.4
does this work to combine the two together?
while not turtle.forward() do
while not turtle.dig() do
turtle.attack()
end
sleep(0.4)
end
7508 posts
Location
Australia
Posted 13 January 2013 - 01:51 PM
yes that works :)/>
EDIT: If you don't want to replace all the turtle.forward() with the for loop, and feel confident enough with your coding skills, look at the following spoiler
Advanced coding, overriding turtle.forward's functionality:Spoiler
Add at the top of your script
local oldF = turtle.forward
turtle.forward = function( times )
if not times then times = 1 end
if type( times ) ~= "number" then error( "Invalid parameter: expected number, got "..type( times ), 2 ) end
for i = 1, times do
while not oldF() do
while not turtle.dig() do
turtle.attacK()
end
end
end
end
Add to the VERY end of your script
turtle.forward = oldF
you can then use it like this
turtle.forward() -- moves it forward once allowing for gravel and mobs
turtle.forward( 4 ) -- moves it forward 4 times allowing for gravel and mobs
turtle.forward( "4" ) -- this is wrong and will error!
Edited on 13 January 2013 - 12:53 PM
18 posts
Posted 13 January 2013 - 02:06 PM
Thanks ill look through that. I like to understand how it works before just using it so that I can branch off of it if need be.
7508 posts
Location
Australia
Posted 13 January 2013 - 02:10 PM
Thanks ill look through that. I like to understand how it works before just using it so that I can branch off of it if need be.
Basically it stores the old forward function so we can restore it later, then it makes forward a new function that moves and checks for gravel just like the code before… there is some validation in there too to see if you called
turtle.forward()
or
turtle.forward( 4 )