Difference between revisions of "Turtle.forward"
From ComputerCraft Wiki
(Replaced content with "Moves the turtle forward.") |
("Created" the page again) |
||
| Line 1: | Line 1: | ||
| − | + | {{Function | |
| + | |name=turtle.forward | ||
| + | |api=turtle | ||
| + | |addon=ComputerCraft | ||
| + | |desc=Attempts to move the turtle forward. | ||
| + | |examples= | ||
| + | {{Example | ||
| + | |desc=Trys 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 | ||
| + | |desc=Trys to move the turtle forward x number of times. X is spezified by the user and if the turtle can't move forward it will break the block infront of it. | ||
| + | |code=Arg = (...) -- gets the param 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 trutle moving the specified amount of times. or Missing parameter. | ||
| + | }} | ||
| + | }} | ||
Revision as of 09:57, 8 July 2012
| Attempts to move the turtle forward. | |
| Syntax | turtle.forward() |
| Returns | nil |
| Part of | ComputerCraft |
| API | turtle |
Examples
| Trys 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. |
| Trys to move the turtle forward x number of times. X is spezified by the user and if the turtle can't move forward it will break the block infront of it. | |
| Code |
Arg = (...) -- gets the param 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 trutle moving the specified amount of times. or Missing parameter. |