Posted 26 July 2012 - 09:05 AM
Hey Guys. First post, first program.
I quarry underground and it gets dark, so I wrote a turtle program to go around and place torches for me..
I'm a program for a living, but LUA is new to me.. Code below:
However I receive the following error:
Line 34 appears to be:
But I can't see anything obvious that stopping it from working
Any ideas guys?
I quarry underground and it gets dark, so I wrote a turtle program to go around and place torches for me..
I'm a program for a living, but LUA is new to me.. Code below:
-- Torcher goes CLOCKWISE round a pit, so place with left side facing a wall
currentSlot = 1 -- Which slot are we currently using?
sides = {} -- Length of cavern sides
sideLength = 0 -- Initial length of sides
topSide = 0 -- Counter to know how far down we are
torchCount = 0
-- Get in the pit
turtle.forward()
turtle.down()
for t = 1,4 do --Loop through all 4 sides to determine hole size
while (turtle.detect() == false) do
turtle.forward()
sideLength = sideLength + 1
end
sides[t] = sideLength
sideLength = 0
turtle.turnRight()
end
-- Here we're back at the starting point and we know the hole side lengths, start placing torches
-- Go down 4 blocks to start
turtle.down()
turtle.down()
turtle.down()
turtle.down()
topSide = 6
while turtle.detectDown() == false do --Continue loop until Bedrock is below
for t=1,4 do --Loops through each cavern side
for tt=1, sides[t] do -- Loops through each section of cavern wall
turtle.forward()
-- if( math.fmod(tt,7) = 0 ) then -- Place a torch
torchCount = torchCount + 1
if torchCount == 7 then
torchCount = 0
if turtle.getItemCount(currentSlot) == 0 then
currentSlot = currentSlot + 1
if currentSlot == 10 then currentSlot = 1
turtle.select(currentSlot)
turtle.placeUp()
end
end
end
turtle.turnRight()
end
turtle.down()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
topSide = topSide + 7
end
-- Lets raise the little fella back to the surface
for t = 1,topSide do
turtle.up()
end
However I receive the following error:
bios:206: [string "Torcher2"]:70: 'end' expected (to close 'while' at line 34)
Line 34 appears to be:
if turtle.getItemCount(currentSlot) == 0 then
But I can't see anything obvious that stopping it from working
Any ideas guys?