Difference between revisions of "Turtle.dig"

From ComputerCraft Wiki
Jump to: navigation, search
(Describe the toolSide argument for turtle.dig. We won't bother with the other dig methods, as they operate the same as this.)
 
(10 intermediate revisions by 7 users not shown)
Line 2: Line 2:
 
{{Function
 
{{Function
 
|name=turtle.dig
 
|name=turtle.dig
|args=
+
|args=[<nowiki/>{{type|string}} toolSide]
 
|api=turtle
 
|api=turtle
|returns=[[boolean]] whether the turtle succeeded in digging.
+
|returns={{Type|boolean}} whether the turtle succeeded in digging, {{type|string}} error message
 
|addon=ComputerCraft
 
|addon=ComputerCraft
|desc=Attempts to dig the block in front of the turtle.
+
|desc=Attempts to dig the block in front of the turtle.  If successful, [[Turtle.suck|suck()]] is automatically called, placing the item in turtle inventory in the selected slot if possible (block type matches and the slot is not a full stack yet), or in the next available slot.<br><br>
 +
 
 +
If a hoe is used to attempt to "dig" a dirt block, it will be tilled instead. Tilling is also possible if the space in front of the turtle is empty but dirt exists below that point.
 +
 
 +
You can pass optionally pass in "left" or "right" to the <var>toolSide</var> argument to determine which tool to dig with, otherwise the turtle will attempt to dig with both tools.
 
|examples=
 
|examples=
 
{{Example
 
{{Example
Line 21: Line 25:
 
}}
 
}}
 
}}
 
}}
 +
 +
==See also==
 +
*[[turtle.digUp]]
 +
*[[turtle.digDown]]
 +
 +
[[Category:Lua_Core_Functions]]

Latest revision as of 10:36, 24 October 2018


Grid Redstone.png  Function turtle.dig
Attempts to dig the block in front of the turtle. If successful, suck() is automatically called, placing the item in turtle inventory in the selected slot if possible (block type matches and the slot is not a full stack yet), or in the next available slot.

If a hoe is used to attempt to "dig" a dirt block, it will be tilled instead. Tilling is also possible if the space in front of the turtle is empty but dirt exists below that point.

You can pass optionally pass in "left" or "right" to the toolSide argument to determine which tool to dig with, otherwise the turtle will attempt to dig with both tools.
Syntax turtle.dig([string toolSide])
Returns boolean whether the turtle succeeded in digging, string error message
Part of ComputerCraft
API turtle

Examples

Grid paper.png  Example
Digs the block in front of the turtle.
Code
print(turtle.dig())
Output true if the turtle could dig the block, false if it could not or no block present.



Grid paper.png  Example
Digs the block in front of the turtle, but only if there is a block to dig (saves time).
Code
if turtle.detect() then
 turtle.dig()
end
Output the turtle digs if there is a block in front.


See also