Posted 24 February 2014 - 07:14 AM
I have no idea why this happens or how it happens but my while loop will no repeat itself. For some reason it will only repeat itself once and once only. Here is the code I am using:
--Variables
local x = 1
local y = 1
local dir = 270
local monitor = peripheral.wrap("bottom")
local modem = peripheral.wrap("back")
local completed = false
local x1, x2, x3, x4, x5, y1, y2, y3, y4, y5, dir1, dir2, dir3, dir4, dir5 = 1
--Print Title
monitor.clear()
monitor.setTextScale(2)
monitor.setCursorPos(10, 1)
monitor.write("Turtle Maze")
monitor.setCursorPos(1, 2)
monitor.write("==============================")
monitor.setCursorPos(1, 3)
monitor.write("Coords:")
monitor.setCursorPos(11, 3)
monitor.write("Direction:")
monitor.setCursorPos(24, 3)
monitor.write("Fuel:")
--Print Coords and Direction
while true do
modem.open(1)
local event1, modemSide1, senderChannel1, replyChannel1, message1, senderDistance1 = os.pullEvent("modem_message")
x = message1
modem.open(2)
local event2, modemSide2, senderChannel2, replyChannel2, message2, senderDistance2 = os.pullEvent("modem_message")
y = message2
monitor.setCursorPos(1, 4)
monitor.write("X:"..x.." Y:"..y)
modem.open(3)
local event3, modemSide3, senderChannel3, replyChannel3, message3, senderDistance3 = os.pullEvent("modem_message")
dir = message3
monitor.setCursorPos(11, 4)
if dir == 0 then
dir = "Right"
elseif dir == 90 then
dir = "Up"
elseif dir == 180 then
dir = "Left"
else
dir = "Down"
end
monitor.write(dir)
--Print Previous Coords and Directions
--Dir
dir5 = dir4
dir4 = dir3
dir3 = dir2
dir2 = dir1
dir1 = dir
monitor.setCursorPos(11, 5)
monitor.write(dir1)
monitor.setCursorPos(11, 6)
monitor.write(dir2)
monitor.setCursorPos(11, 7)
monitor.write(dir3)
monitor.setCursorPos(11, 8)
monitor.write(dir4)
montior.setCursorPos(11, 9)
monitor.write(dir5)
--X, Y
x5 = x4
x4 = x3
x3 = x2
x2 = x1
x1 = x
y5 = y4
y4 = y3
y3 = y2
y2 = y1
y1 = y
monitor.setCursorPos(1, 5)
monitor.write("X: "..x1.." Y: "..y1)
monitor.setCursorPos(1, 6)
monitor.write("X: "..x2.." Y: "..y2)
monitor.setCursorPos(1, 7)
monitor.write("X: "..x3.." Y: "..y3)
monitor.setCursorPos(1, 8)
monitor.write("X: "..x4.." Y: "..y4)
monitor.setCursorPos(1, 9)
monitor.write("X: "..x5.." Y: "..y5)
completed = false
end
See if you guys can figure it out.