Difference between revisions of "Turtle.attack"

From ComputerCraft Wiki
Jump to: navigation, search
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{stub}}
 
'''This page is currently unfinished.'''
 
----
 
 
{{Function
 
{{Function
 
|name=turtle.attack
 
|name=turtle.attack
 
|api=turtle
 
|api=turtle
|returns=[[boolean]] whether the turtle succeeded in attacking
+
|args=[<nowiki/>{{type|string}} toolSide]
 +
|returns=[[boolean_(type)|boolean]] whether the turtle succeeded in attacking forward
 
|addon=ComputerCraft
 
|addon=ComputerCraft
|desc=Attempts to attack the block in front.
+
|desc=Attempts to attack in front of the turtle. You can pass optionally pass in "left" or "right" to the <var>toolSide</var> argument to determine which tool to attack with, otherwise the turtle will attempt to attack with both tools.
 
|examples=
 
|examples=
 
{{Example
 
{{Example
|desc=Tries to attack a mob/player in front and outputs whether it worked or not.
+
|desc=Tries to attack in front of the turtle and outputs whether it worked or not.
 
|code=if turtle.attack() then
 
|code=if turtle.attack() then
   [[print]] ("Turtle attacked in Front.")
+
   [[print]] ("Turtle attacked in front.")
 
  else
 
  else
   [[print]] ("Turtle Could not attack.")
+
   [[print]] ("Turtle could not attack.")
 
  end
 
  end
|output= Turtle attacked in Front. or Turtle Could not attack.
+
|output= Turtle attacked in front. or Turtle could not attack.
 
}}
 
}}
 +
 +
}}
 +
 +
==See also==
 +
*[[turtle.attackUp]]
 +
*[[turtle.attackDown]]
 +
 +
[[Category:Lua_Core_Functions]]

Latest revision as of 10:34, 24 October 2018

Grid Redstone.png  Function turtle.attack
Attempts to attack in front of the turtle. You can pass optionally pass in "left" or "right" to the toolSide argument to determine which tool to attack with, otherwise the turtle will attempt to attack with both tools.
Syntax turtle.attack([string toolSide])
Returns boolean whether the turtle succeeded in attacking forward
Part of ComputerCraft
API turtle

Examples

Grid paper.png  Example
Tries to attack in front of the turtle and outputs whether it worked or not.
Code
if turtle.attack() then
 print ("Turtle attacked in front.")
else
 print ("Turtle could not attack.")
end
Output Turtle attacked in front. or Turtle could not attack.


See also