http://www.computercraft.info/wiki/api.php?action=feedcontributions&user=211.30.220.156&feedformat=atomComputerCraft Wiki - User contributions [en]2024-03-28T09:22:29ZUser contributionsMediaWiki 1.24.1http://www.computercraft.info/wiki/index.php?title=Turtle_Lumberjack_(tutorial)&diff=1412Turtle Lumberjack (tutorial)2012-04-29T20:31:04Z<p>211.30.220.156: /* What are Turtle Lumberjacks? */</p>
<hr />
<div><br />
== Turtle Lumberjack ==<br />
=== Introduction ===<br />
Welcome to this [[:Category:Tutorials|tutorial]] about Turtle Lumberjacks.<br />
<br />
=== What are Turtle Lumberjacks? ===<br />
Turtle Lumberjacks are mining turtles that are programmed to chop down a tree.<br />
They are placed in front of a tree and then activated, and then you watch the tree get chopped down!<br />
This can be also used to destroy pillars of sandstone, sand etc.<br />
<br />
== The Code ==<br />
First, we start with the basics.<br />
<code><br />
while turtle.detect() do<br />
<br />
end<br />
</code><br />
This makes it loop while there is a block in front of it.<br />
Let's add the digging part to it.<br />
<code><br />
while turtle.detect() do<br />
turtle.dig()<br />
turtle.up()<br />
end<br />
</code><br />
This makes it dig the block if it is detected, then move up.<br />
Let's add the print function to print what the turtle is doing.<br />
<code><br />
while turtle.detect() do<br />
turtle.dig()<br />
print("Digging the block")<br />
turtle.up()<br />
print("Moving up")<br />
end<br />
</code><br />
There we go!<br />
Let's make it come back down when there is no more blocks to be chopped, or there is a roof above it!<br />
<code><br />
while turtle.detect() do<br />
turtle.dig()<br />
print("Digging the block")<br />
turtle.up()<br />
print("Moving up")<br />
end<br />
while not turtle.detect() and not turtle.detectDown() do<br />
turtle.down()<br />
print("Moving down")<br />
end<br />
</code><br />
This makes it check that while there are no blocks to be chopped and it can go down, it goes down.<br />
Let's add a notification about the job being done.<br />
<code><br />
while turtle.detect() do<br />
turtle.dig()<br />
print("Digging the block")<br />
turtle.up()<br />
print("Moving up")<br />
end<br />
while not turtle.detect() and not turtle.detectDown() do<br />
turtle.down()<br />
print("Moving down")<br />
end<br />
print("Job done!")<br />
</code><br />
<br />
There you go! Now it is done!<br />
Your turtle will dig the tree up and then come back down.<br />
<br />
('''Helpful tip:''' Save this to your ComputerCraft/lua/rom/programs folder, then it will be on all turtles.)<br />
<br />
== Category & Author ==<br />
A tutorial by [[User:TheVarmari|TheVarmari]]. Feel free to correct any mistakes!<br />
[[Category:Tutorials]]</div>211.30.220.156http://www.computercraft.info/wiki/index.php?title=Turtle_Lumberjack_(tutorial)&diff=1411Turtle Lumberjack (tutorial)2012-04-29T20:29:58Z<p>211.30.220.156: /* The Code */</p>
<hr />
<div><br />
== Turtle Lumberjack ==<br />
=== Introduction ===<br />
Welcome to this [[:Category:Tutorials|tutorial]] about Turtle Lumberjacks.<br />
<br />
=== What are Turtle Lumberjacks? ===<br />
Turtle Lumberjacks are mining turtles that are programmed to chop down a tree.<br />
They are placed in front of a tree and then activated, and then you watch the tree get chop down!<br />
This can be also used to destroy pillars of sandstone, sand etc.<br />
<br />
== The Code ==<br />
First, we start with the basics.<br />
<code><br />
while turtle.detect() do<br />
<br />
end<br />
</code><br />
This makes it loop while there is a block in front of it.<br />
Let's add the digging part to it.<br />
<code><br />
while turtle.detect() do<br />
turtle.dig()<br />
turtle.up()<br />
end<br />
</code><br />
This makes it dig the block if it is detected, then move up.<br />
Let's add the print function to print what the turtle is doing.<br />
<code><br />
while turtle.detect() do<br />
turtle.dig()<br />
print("Digging the block")<br />
turtle.up()<br />
print("Moving up")<br />
end<br />
</code><br />
There we go!<br />
Let's make it come back down when there is no more blocks to be chopped, or there is a roof above it!<br />
<code><br />
while turtle.detect() do<br />
turtle.dig()<br />
print("Digging the block")<br />
turtle.up()<br />
print("Moving up")<br />
end<br />
while not turtle.detect() and not turtle.detectDown() do<br />
turtle.down()<br />
print("Moving down")<br />
end<br />
</code><br />
This makes it check that while there are no blocks to be chopped and it can go down, it goes down.<br />
Let's add a notification about the job being done.<br />
<code><br />
while turtle.detect() do<br />
turtle.dig()<br />
print("Digging the block")<br />
turtle.up()<br />
print("Moving up")<br />
end<br />
while not turtle.detect() and not turtle.detectDown() do<br />
turtle.down()<br />
print("Moving down")<br />
end<br />
print("Job done!")<br />
</code><br />
<br />
There you go! Now it is done!<br />
Your turtle will dig the tree up and then come back down.<br />
<br />
('''Helpful tip:''' Save this to your ComputerCraft/lua/rom/programs folder, then it will be on all turtles.)<br />
<br />
== Category & Author ==<br />
A tutorial by [[User:TheVarmari|TheVarmari]]. Feel free to correct any mistakes!<br />
[[Category:Tutorials]]</div>211.30.220.156