This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
t3stimony's profile picture

Turtle Tree Cutting

Started by t3stimony, 01 May 2013 - 06:22 PM
t3stimony #1
Posted 01 May 2013 - 08:22 PM
i am trying to make a tree farm with my turtle.
my code is:
for i = 0, x do
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.select(log)
if turtle. compare() then
turtle. dig()
turtle.forward()

it says i need an end after if, but i want it inside my for loop
Lyqyd #2
Posted 02 May 2013 - 12:48 PM
What do you want inside your for loop? I'm not sure where you expect that code to be split. Have you tried putting two `end`s at the end of the program? That may do what you're looking for, or it may not. We would need a better explanation to help further.
The_Awe35 #3
Posted 02 May 2013 - 12:55 PM
When you use loops (for, while, repeat until) or a conditional statement (if then) you declare them at the start, and then to tell them when to end with a "end". so your program would be:


for i = 1,x do --I'm not sure if your for loop would messup if it is 0 instead of 1, but you should start with a 1.
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.select(1) --unless you want the log variable to change, you should just keep it at a set slot.
  if turtle.compare() then --note that I made this farther out. This is to help the readability of the code.
  turtle.dig()
  turtle.forward()
  end --this ends the conditional statement
end --this ends the for statement