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

can you help me please?

Started by Mat4297, 21 July 2016 - 01:05 PM
Mat4297 #1
Posted 21 July 2016 - 03:05 PM
I am a beginner and do not know how to program a turtle to dig, would you be able to create me a simple command to make them dig a tunnel?
I would need that the turtle dug the first three blocks in front of her, then randomly chooses one of the three directions (front, left and right), and repeat the command indefinitely.
I would need more than scaricasse automatically the full inventory, but that would take in the first inventory of coal and the second held torches that will place every 10 blocks.
my goal would be to get a result in the form of a grid, the size of which will be decided before starting the turtle, each block should be 2x2 and surrounded entirely by a corridor.
Max #2
Posted 21 July 2016 - 03:50 PM
Repeating infinitely can be done by using a while loop:


while true do
--your code
end

you can use math.random for random direction

direction = math.random(1,3)
if direction == 1 then
elseif direction == 2 then
...
moving, digging and turning works like this:

--Move
turtle.forward()
--Turn
turtle.turnRight()
--Dig
turtle.dig()