Difference between revisions of "Turtle Lumberjack (tutorial)"
TheVarmari (Talk | contribs) (→Introduction) |
m (Fix code blocks being badly formatted) |
||
(9 intermediate revisions by 4 users not shown) | |||
Line 2: | Line 2: | ||
== Turtle Lumberjack == | == Turtle Lumberjack == | ||
=== Introduction === | === Introduction === | ||
− | Welcome to this [[Category:Tutorials|tutorial]] about Turtle Lumberjacks. | + | Welcome to this [[:Category:Tutorials|tutorial]] about Turtle Lumberjacks. |
=== What are Turtle Lumberjacks? === | === What are Turtle Lumberjacks? === | ||
Turtle Lumberjacks are mining turtles that are programmed to chop down a tree. | Turtle Lumberjacks are mining turtles that are programmed to chop down a tree. | ||
− | They are placed in front of a tree and then activated, and then you watch the tree get | + | They are placed in front of a tree and then activated, and then you watch the tree get chopped down! |
This can be also used to destroy pillars of sandstone, sand etc. | This can be also used to destroy pillars of sandstone, sand etc. | ||
== The Code == | == The Code == | ||
First, we start with the basics. | First, we start with the basics. | ||
− | + | ||
while turtle.detect() do | while turtle.detect() do | ||
end | end | ||
− | + | ||
This makes it loop while there is a block in front of it. | This makes it loop while there is a block in front of it. | ||
Let's add the digging part to it. | Let's add the digging part to it. | ||
− | + | ||
while turtle.detect() do | while turtle.detect() do | ||
turtle.dig() | turtle.dig() | ||
turtle.up() | turtle.up() | ||
end | end | ||
− | + | ||
This makes it dig the block if it is detected, then move up. | This makes it dig the block if it is detected, then move up. | ||
Let's add the print function to print what the turtle is doing. | Let's add the print function to print what the turtle is doing. | ||
− | + | ||
while turtle.detect() do | while turtle.detect() do | ||
turtle.dig() | turtle.dig() | ||
Line 33: | Line 33: | ||
print("Moving up") | print("Moving up") | ||
end | end | ||
− | + | ||
There we go! | There we go! | ||
Let's make it come back down when there is no more blocks to be chopped, or there is a roof above it! | Let's make it come back down when there is no more blocks to be chopped, or there is a roof above it! | ||
− | + | ||
while turtle.detect() do | while turtle.detect() do | ||
turtle.dig() | turtle.dig() | ||
Line 43: | Line 43: | ||
print("Moving up") | print("Moving up") | ||
end | end | ||
− | |||
while not turtle.detect() and not turtle.detectDown() do | while not turtle.detect() and not turtle.detectDown() do | ||
turtle.down() | turtle.down() | ||
print("Moving down") | print("Moving down") | ||
end | end | ||
− | + | ||
This makes it check that while there are no blocks to be chopped and it can go down, it goes down. | This makes it check that while there are no blocks to be chopped and it can go down, it goes down. | ||
Let's add a notification about the job being done. | Let's add a notification about the job being done. | ||
− | + | ||
while turtle.detect() do | while turtle.detect() do | ||
turtle.dig() | turtle.dig() | ||
Line 58: | Line 57: | ||
print("Moving up") | print("Moving up") | ||
end | end | ||
− | |||
while not turtle.detect() and not turtle.detectDown() do | while not turtle.detect() and not turtle.detectDown() do | ||
turtle.down() | turtle.down() | ||
print("Moving down") | print("Moving down") | ||
end | end | ||
− | |||
print("Job done!") | print("Job done!") | ||
− | + | ||
There you go! Now it is done! | There you go! Now it is done! | ||
− | Your turtle will dig the tree | + | Your turtle will dig the tree up and then come back down. |
− | ('''Helpful tip:''' Save this to your | + | ('''Helpful tip:''' Save this to your ComputerCraft/lua/rom/programs folder, then it will be on all turtles.) |
− | + | [[Category:Tutorials]] | |
− | + | ||
− | [Category:Tutorials] | + |
Latest revision as of 21:58, 12 September 2017
Turtle Lumberjack
Introduction
Welcome to this tutorial about Turtle Lumberjacks.
What are Turtle Lumberjacks?
Turtle Lumberjacks are mining turtles that are programmed to chop down a tree. They are placed in front of a tree and then activated, and then you watch the tree get chopped down! This can be also used to destroy pillars of sandstone, sand etc.
The Code
First, we start with the basics.
while turtle.detect() do end
This makes it loop while there is a block in front of it. Let's add the digging part to it.
while turtle.detect() do turtle.dig() turtle.up() end
This makes it dig the block if it is detected, then move up. Let's add the print function to print what the turtle is doing.
while turtle.detect() do turtle.dig() print("Digging the block") turtle.up() print("Moving up") end
There we go! Let's make it come back down when there is no more blocks to be chopped, or there is a roof above it!
while turtle.detect() do turtle.dig() print("Digging the block") turtle.up() print("Moving up") end while not turtle.detect() and not turtle.detectDown() do turtle.down() print("Moving down") end
This makes it check that while there are no blocks to be chopped and it can go down, it goes down. Let's add a notification about the job being done.
while turtle.detect() do turtle.dig() print("Digging the block") turtle.up() print("Moving up") end while not turtle.detect() and not turtle.detectDown() do turtle.down() print("Moving down") end print("Job done!")
There you go! Now it is done!
Your turtle will dig the tree up and then come back down.
(Helpful tip: Save this to your ComputerCraft/lua/rom/programs folder, then it will be on all turtles.)