Posted 13 February 2013 - 01:48 PM
I need help with this function I'm writing to control a system of computers that will operate my elevator I've made in conjunction with Redpower. The system is supposed to work with a computer that is actually on the elevator, the part of the code that starts with "x == "onboard"", that you enter what floor you want to go to, and then that computer is supposed to tell the "control" computer what floor it wants to go to. Then the control computer is supposed to check the disk drive, whose "floors" file has been edited by the "catlog" computer to add floors to it, to see what the Z coordinate is of the destination floor. The control computer then is supposed to send this Z coordinate number to the "onboard" computer which is supposed to check to see whether or not it is above or below the destination floor, and then, depending on where it is relative to the destination floor, the "onboard" computer is supposed to broadcast an "up" or "down" command to a Frame Motor Controller computer, "FMcontroller", which'll send a redstone pulse to the appropriate frame motors to send the elevator either up or down. The function's code looks like this:
My problem occurs when I enter what floor I want to go to into the "onboard" computer. I'll put in a number, and then the "control" computer claims that the floppy disc directory doesn't exist and won't give the Z coordinate. What am I doing wrong? I've stared and tried to fix this function for hours, and my eyes are starting to hurt and I'm getting a headache… I just don't know what else to do.
function elevator(x)
if x == "catlog" then
while disk.isPresent("right") == false do
term.clear()
term.setCursorPos(1,1)
print ("Please Insert Floors Disk To Catalogue")
sleep(2)
end
while true do
term.clear()
term.setCursorPos(1,1)
print("Add a floor?")
floornum = read()
print("Floor depth? (Z Coordinate)")
floordep = read()
floornum = "f"..floornum
floordep = "d"..floordep
floorloc = floornum..floordep
if fs.isDir("disk\floors") == nil then
fs.makeDir("disk\floors")
end
elecon = fs.open("disk\floors", "a")
elecon.write(floorloc)
sleep(2)
end
end
if x == "control" then
thor.wireless()
while true do
goto = 0
while goto == 0 do
_,goto,_ = rednet.receive()
if string.sub(goto, 1, 6) ~= "destin" then
goto = 0
end
end
goto = string.sub(goto, 7)
goto = "f"..goto
if fs.isDir("disk\floors") == false then
rednet.broadcast("ERROR: SET UP FLOOR CATLOG OR INSERT FLOORS DISK")
else
elecon = fs.open("disk\floors", "r")
floorcat = elecon.read()
gotoS,gotoE = string.find(floorcat, goto)
goto = string.sub(floorcat, gotoE+1, gotoE+2)
rednet.broadcast(goto)
end
end
end
if x == "onboard" then
thor.wireless()
while true do
term.clear()
term.setCursorPos(1,1)
print("Destination? (Num of Floor You Would Like To Go To)")
destin = read()
destin = "destin"..destin
rednet.broadcast("destin")
destin = 0
it = 0
while destin == 0 and it <= 25 do
_,destin,_ = rednet.receive(7)
if string.sub(destin, 1, 1) ~= "d" then
destin = 0
end
it = it+1
end
if it < 25 then
destin = string.sub(destin, 2)
_,_,currnt = gps.locate()
if currnt > destin then
while currnt > destin do
rednet.broadcast("down")
sleep(2)
_,_,currnt = gps.locate()
end
elseif currnt < destin then
while currnt < destin do
rednet.broadcast("up")
sleep(2)
_,_,currnt = gps.locate()
end
elseif currnt == destin then
print("Already at floor")
end
print("YOU HAVE ARRIVED!")
sleep(4)
else
print("There is an ERROR in the system!")
end
end
end
if x == "FMcontroller" then
thor.wireless()
while true do
cmd = 0
while cmd == 0 do
_,cmd,_ = rednet.receive()
if cmd ~= "up" and cmd ~= "down" then
cmd = 0
end
end
if cmd == "up" then
redstone.setOutput("right", true)
redstone.setOutput("right", false)
end
if cmd == "down" then
redstone.setOutput("left", true)
redstone.setOutput("left", false)
end
end
end
end
My problem occurs when I enter what floor I want to go to into the "onboard" computer. I'll put in a number, and then the "control" computer claims that the floppy disc directory doesn't exist and won't give the Z coordinate. What am I doing wrong? I've stared and tried to fix this function for hours, and my eyes are starting to hurt and I'm getting a headache… I just don't know what else to do.