Posted 21 February 2014 - 11:16 PM
So I was making a little test program just for a bit of fun and to refresh my memory on LUA programming and ran into a slight problem while testing it. Every time I execute the program it returns the error:
bios:339: [string "maze"]:30: 'end' expected (to close 'while' at line 9)
I understand that it is telling me to add an end to close the while loop I started at line 9. However, I have a lot more code that must be executed within the while loop and so if I close it that code will not be executed. So could one of you Pros check my code and find out what to do to fix this error.
--Variables
local completed = false
local modem = peripheral.wrap("right")
local x = 1
local y = 1
local dir = 270
--Movement
while completed == false do
if turtle.getFuelLevel() < 16 then
turtle.refuel(1)
end
if turtle.detect() then
turtle.turnLeft()
dir = dir + 90
if turtle.detect() then
turtle.turnRight()
turtle.turnRight()
dir = dir - 180
if turtle.detect() then
turtle.turnRight()
dir = dir - 90
turtle.forward()
end
else turtle.forward()
end
else turtle.forward()
end
else turtle.forward()
end
--Send Coordinates
if dir >= 360 then
dir = dir - 360
end
if dir < 0 then
dir = dir + 360
end
if dir == 0 then
x = x + 1
end
else if dir == 90 then
y = y + 1
end
else if dir == 180 then
x = x - 1
end
else if dir == 270 then
y = y - 1
end
end
modem.transmit(1, 1, x)
modem.transmit(2, 2, y)
--Check at end
turtle.select(16)
if turtle.compareDown() then
turtle.up()
turtle.up()
turtle.up()
completed = true
shell.run("dance")
end
turtle.select(1)
print("X: "..x.." Y: "..y)
end