13 posts
Posted 09 February 2013 - 11:03 AM
I am having issues with entities (such as pigs) getting in the way of the turtle and changing the path of the program. Gravel and sand falling in front of it do this.
This is the code that i have but it does not work.
while turtle.detect() do
turtle.dig()
turtle.attack()
end
436 posts
Posted 09 February 2013 - 11:32 AM
Detect doesn't detect entities. And make it sleep for about .5 seconds. If you're making a tunnel/quarry system, put it as a check outcome.
ie. (in pseudocode)
if not move then
if not detect then
if not dig then
if not attack then
print("Bedrock")
end
end
end
end
13 posts
Posted 09 February 2013 - 11:35 AM
Ok. is this all i would need to enter into the code?
1522 posts
Location
The Netherlands
Posted 09 February 2013 - 12:35 PM
Try this:
while not turtle.forward() do
if turtle.dig == false then
if turtle.attack() == false then
if turtle.detect() then
print("Bedrock in my way")
-- Your code to manouvre away from bedrock, or break or something
end
end
end
end
sleep(0) -- prevents the error too long without yielding
21 posts
Posted 09 February 2013 - 12:59 PM
turtle.dig == false
will compare and address with a boolean
but even
turtle.dig() == false
is better been written as
not turtle.dig()
sleep(0) does not seem to do anything here since it's not in the loop
EDIT: afaik a falling block of gravel in that situation would let everything in that loop fail until it's done falling so a sleep(0.25) (or sth like that) in the else part of the if-detect would probably be best
13 posts
Posted 09 February 2013 - 02:07 PM
so if I do this…
while not turtle.forward() do
if turtle.dig == false then
if turtle.attack() == false then
if turtle.detect() then
print("Bedrock in my way")
-- Your code to manouvre away from bedrock, or break or something
else
sleep(0.25)
end
end
end
end
Gravel, sand and entities will not affect the path?
8543 posts
Posted 09 February 2013 - 03:04 PM
--this code assumes you have already dug once if necessary, so handles gravel and entities
while not turtle.forward() do
local attempts = 0
while turtle.detect() do
attempts = attempts + 1
turtle.dig()
sleep(0.6)
if attempts > 8 then break end --probably bedrock.
end
while turtle.attack() do
sleep(0.5)
end
end