Difference between revisions of "Turtle.forward"
From ComputerCraft Wiki
m (forward chuck) |
(Adding "see also".) |
||
(14 intermediate revisions by 9 users not shown) | |||
Line 2: | Line 2: | ||
|name=turtle.forward | |name=turtle.forward | ||
|api=turtle | |api=turtle | ||
− | |returns=[[boolean]] whether the turtle succeeded in moving forward | + | |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=if turtle.forward() then | |code=if turtle.forward() then | ||
[[print]] ("Turtle moved forward.") | [[print]] ("Turtle moved forward.") | ||
Line 16: | Line 16: | ||
}} | }} | ||
{{Example | {{Example | ||
− | |desc= | + | |desc=Tries to move the turtle forward a number of times. The times to move forward is specified by the user. |
− | |code= | + | |code=local distance = ... -- gets the first argument from the user |
− | if | + | if distance ~= nil then |
− | + | distance = [[tonumber]] (distance) -- make it a number | |
− | + | for i = 1, distance do | |
− | + | ||
− | + | ||
− | + | ||
turtle.forward() | turtle.forward() | ||
− | |||
− | |||
end | end | ||
else | else | ||
− | [[print]] (" | + | [[print]] ("Did not specify distance.") |
end | end | ||
− | |output= Either the | + | |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. |