Difference between revisions of "Turtle.forward"
From ComputerCraft Wiki
(Created page with "{{lowercase}} {{Function |name=turtle.forward |args= |api=turtle |returns=boolean whether the turtle succeeded in moving forwards |addon=ComputerCraft |desc=Attempts to mo...") |
(Adding "see also".) |
||
(20 intermediate revisions by 13 users not shown) | |||
Line 1: | Line 1: | ||
− | |||
{{Function | {{Function | ||
|name=turtle.forward | |name=turtle.forward | ||
− | |||
|api=turtle | |api=turtle | ||
− | |returns=[[boolean]] whether the turtle succeeded in moving | + | |returns=[[boolean_(type)|boolean]] whether the turtle succeeded in moving forward |
|addon=ComputerCraft | |addon=ComputerCraft | ||
|desc=Attempts to move the turtle forward. | |desc=Attempts to move the turtle forward. | ||
|examples= | |examples= | ||
{{Example | {{Example | ||
− | |desc= | + | |desc=Tries to move the turtle forward and outputs whether it worked or not. |
− | |code= | + | |code=if turtle.forward() then |
− | |output= | + | [[print]] ("Turtle moved forward.") |
+ | else | ||
+ | [[print]] ("Turtle didn't move forward.") | ||
+ | end | ||
+ | |output= Turtle moved forward. or Turtle didn't move forward. | ||
+ | }} | ||
+ | {{Example | ||
+ | |desc=Tries to move the turtle forward a number of times. The times to move forward is specified by the user. | ||
+ | |code=local distance = ... -- gets the first argument from the user | ||
+ | if distance ~= nil then | ||
+ | distance = [[tonumber]] (distance) -- make it a number | ||
+ | for i = 1, distance do | ||
+ | turtle.forward() | ||
+ | end | ||
+ | else | ||
+ | [[print]] ("Did not specify distance.") | ||
+ | end | ||
+ | |output= Either the turtle moving the specified amount of times or missing parameter. | ||
+ | }} | ||
+ | {{Example | ||
+ | |desc=Digs until the turtle can move forward. | ||
+ | |code=while not turtle.forward() do | ||
+ | [[turtle.dig]]() | ||
+ | end | ||
+ | |output= The turtle moves forward. | ||
}} | }} | ||
}} | }} | ||
+ | |||
+ | ==See also== | ||
+ | *[[turtle.back]] | ||
+ | |||
+ | [[Category:Lua_Core_Functions]] |
Latest revision as of 23:09, 26 April 2015
Function turtle.forward | |
Attempts to move the turtle forward. | |
Syntax | turtle.forward() |
Returns | boolean whether the turtle succeeded in moving forward |
Part of | ComputerCraft |
API | turtle |
Examples
Example | |
Tries to move the turtle forward and outputs whether it worked or not. | |
Code |
if turtle.forward() then print ("Turtle moved forward.") else print ("Turtle didn't move forward.") end |
Output | Turtle moved forward. or Turtle didn't move forward. |
Example | |
Tries to move the turtle forward a number of times. The times to move forward is specified by the user. | |
Code |
local distance = ... -- gets the first argument from the user if distance ~= nil then distance = tonumber (distance) -- make it a number for i = 1, distance do turtle.forward() end else print ("Did not specify distance.") end |
Output | Either the turtle moving the specified amount of times or missing parameter. |
Example | |
Digs until the turtle can move forward. | |
Code |
while not turtle.forward() do turtle.dig() end |
Output | The turtle moves forward. |