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

Leaf Clearing Turtle

Started by neiromaru, 13 July 2013 - 12:06 PM
neiromaru #1
Posted 13 July 2013 - 02:06 PM
I'm using steve's carts to farm trees, but leaves are aparently opaque enough to block the solar panels on the cart.
Therefore I'm trying to use a turtle to clear the areas above the 22x6 rectanlge of track.
I know very little about turtle programming, but this is what I've cobbled together from a few bit of code I've found while searching the net.

I'd appreciate any advice on how I could optimize this. I've never used for loops before so I'm not even sure if this will work as is.

EDIT: tried running the program, it returns: "bios:338: [string "test"]:40: 'in' expected"
removing the final for loop (which is what's on line 40) makes it run properly, but of course removes the part where the turtle resets to it's initial position.


while true do
local h = 20
for DoNotChangeThis=1, h do

  local q = 22
  for DoNotChangeThis=1, q do
  turtle.dig()
  turtle.forward()
  end
  turtle.turnRight()

  local w = 6
  for DoNotChangeThis=1, w do
  turtle.dig()
  turtle.forward()
  end

  turtle.turnRight()

  local e = 22
  for DoNotChangeThis=1, e do
  turtle.dig()
  turtle.forward()
  end

  turtle.turnRight()

  local r = 6
  for DoNotChangeThis=1, r do
  turtle.dig()
  turtle.forward()
  end
  turtle.turnRight()
  turtle.up()
end
local t = 20
for DoNotChangeThis, t do
  turtle.down()
end
end
Lyqyd #2
Posted 15 July 2013 - 12:41 PM
Split into new topic.
Grim Reaper #3
Posted 16 July 2013 - 12:48 AM
On line 40 you have the following code:


for DoNotChangeThis, t do

The interpreter expects some kind of iterator function like pairs or ipairs which is used with the 'in' keyword. This is because you haven't initialized DoNotChangeThis.
Apfeldstrudel #4
Posted 16 July 2013 - 09:33 AM
In for nested for loops, many use

for i=1, 10
    for j = 1,10
        Do stuff
    end
End

Using i for the outer loop, j for the next etc.

Forgot do.. Cant bother