Difference between revisions of "Turtle.forward"
From ComputerCraft Wiki
(Fixed some typoes) |
(new example) |
||
| Line 32: | Line 32: | ||
end | end | ||
|output= Either the turtle moving the specified amount of times or missing parameter. | |output= Either the turtle moving the specified amount of times or missing parameter. | ||
| + | }} | ||
| + | {{Example | ||
| + | |desc=Digs until the turtle can move forward. | ||
| + | |code=if not turtle.forward() then | ||
| + | repeat | ||
| + | turtle.dig() | ||
| + | until turtle.forward() | ||
| + | end | ||
| + | |output= The turtle moves forward. | ||
}} | }} | ||
}} | }} | ||
Revision as of 21:01, 24 July 2012
| Attempts to move the turtle forward. | |
| Syntax | turtle.forward() |
| Returns | boolean whether the turtle succeeded in moving forward |
| Part of | ComputerCraft |
| API | turtle |
Examples
| 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. |
| Tries to move the turtle forward x number of times. X is specified by the user and if the turtle can't move forward it will break the block infront of it. | |
| Code |
Arg = (...) -- gets the parameters from the user if Arg ~= nil then Arg = tonumber (Arg) -- make it a number a = 1 while a <= Arg do if not turtle.forward() then turtle.dig() turtle.forward() end a = a + 1 end else print ("Missing parameter.") end |
| Output | Either the turtle moving the specified amount of times or missing parameter. |
| Digs until the turtle can move forward. | |
| Code |
if not turtle.forward() then repeat turtle.dig() until turtle.forward() end |
| Output | The turtle moves forward. |