Posted 21 December 2012 - 08:58 AM
Dear LUA Pro's,
I'm having a bit of an issue getting a piece of code to work, even after browsing around these forums for what feels like hours.
The program is designed to control an elevator built with the mod ugocraft, and involves computers on every floor, combined with a central server to process rednet messages
The problem I'm having involves the program that is supposed to wait for one of four possible events to happen:
1. It receives a rednet message, containing a number that when compared to it's own floor ID tells it whether or not to turn on a rs signal
2. It receives a redstone pulse from the left side, telling it to send a rednet message to the server, 'calling' the elevator
3. It receives user input, in the form of the target floor number, e.g. 1,0 or -8, and sends the associated number the server
4. It receives a redstone pulse from the right side, terminating the program
The problem I'm having is that when the program runs, I cannot enter any input, nor will supplying a redstone signal on any side have an effect.
I'm hoping for any feedback that could help me fix and improve this program!
The client program can be found here, and the server program here
Main part of client program (not full program!):
I'm having a bit of an issue getting a piece of code to work, even after browsing around these forums for what feels like hours.
The program is designed to control an elevator built with the mod ugocraft, and involves computers on every floor, combined with a central server to process rednet messages
The problem I'm having involves the program that is supposed to wait for one of four possible events to happen:
1. It receives a rednet message, containing a number that when compared to it's own floor ID tells it whether or not to turn on a rs signal
2. It receives a redstone pulse from the left side, telling it to send a rednet message to the server, 'calling' the elevator
3. It receives user input, in the form of the target floor number, e.g. 1,0 or -8, and sends the associated number the server
4. It receives a redstone pulse from the right side, terminating the program
The problem I'm having is that when the program runs, I cannot enter any input, nor will supplying a redstone signal on any side have an effect.
I'm hoping for any feedback that could help me fix and improve this program!
The client program can be found here, and the server program here
Main part of client program (not full program!):
function listen()
while true do
local sendID, obj, distance = rednet.receive()
if sendID == serverID then
if obj >= floor then
rs.setOutput("bottom", true)
else
rs.setOutput("bottom", false)
end
end
end
end
function call()
while true do
if rs.getInput("left") == true then
rednet.send(serverID, "call")
end
end
end
function input()
while true do
local input = read()
if input == "quit" then
banana = false
shell.quit()
end
for k,v in pairs(floortable) do
if v == input then
rednet.send(serverID, k)
else
term.setCursorPos(4,12)
term.write("Invalid floor number")
end
end
end
end
function finish()
if rs.getInput("right") == true then
shell.exit()
end
end
while banana == true do
gui()
parallel.waitForAny(listen, call, input, finish)
end