Turtle Tutorial

From ComputerCraft Wiki
Jump to: navigation, search

This tutorial will teach you the functions of the Turtle API, and also will teach you how to make your first turtle program.

Turtle

The Turtle API is used to work with your Turtles. Here is a list of the complete Turtle API

For our program, we will use turtle.refuel(),turtle.detectDown(), turtle.digDown(), turtle.down(), turtle.forward(), and turtle.placeDown(). It is recommended that you learn what these method do before messing with Turtles.

The Program

So, for you to make the Turtle program, first craft a Turtle.


iron_ingot

iron_ingot

iron_ingot

iron_ingot

Computer

chest

iron_ingot

iron_ingot

iron_ingot

turtle



Then make a Mining Turtle.



turtle


diamond_pickaxe




mining_turtle




Then, place it anywhere you want. Right click it and type 'edit MyFirstTurtleProgram'. You don't have to call it 'MyFirstTurtleProgram'; It can be whatever you want. So, inside the file, type

turtle.refuel()
print("Refueled turtle!")
while turtle.detectDown() do
    print("Digging down!")
    turtle.digDown()
    print("Going down!")
    turtle.down()
    print("Digging forward!")
    turtle.dig()
    print("Going forward!")
    turtle.forward()
end

To save the program, press CTRL and select SAVE with the Arrow Keys. After that, type MyFirstTurtleProgram (or whatever you called your program).

If you want a spiral drill formation that allows you to be able to retrieve the turtle after its done mining, do the same as above but when editing the program type:

turtle.refuel()
while turtle.detectDown() do
    turtle.dig()
    turtle.digDown()
    turtle.down()
    turtle.dig()
    turtle.forward()
    turtle.turnLeft()
end

Explanation

The line turtle.refuel() refuels the Turtle so that it can move.

The line while turtle.detectDown() do makes the program run until there is no block underneath the Turtle.

The turtle.digDown() will make the Turtle dig down.

The part where it says turtle.forward() will make the Turtle go forward.

The line that says turtle.dig() will make the Turtle dig forward.


NOTE: this should be running on a mining turtle, or it wont work!

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox