Greetings,
I've been working on recreating an elevator on my SMP server that I have earlier built (succesfully) in SSP.
The set up is quite simple. There's a Computer at the top and bottom platforms, which have the programs 'down' and 'up. Both of which are a very simple 2 line program.
rednet.open("back")
rednet.broadcast("down")
And 'up' for the up program, naturally.
The workhorse is on the computer that controls the Elevator's carriage. The program's code is a little dirty and could definitely be written better, but my priority is to have something working first, I can clean it up later.
Here;
local id
local msg
local rv
local emsg
-- Open for rednet.
rednet.open("top")
-- Do we have an order?
if fs.exists("/var/move") then
fh = fs.open("/var/move", "r")
direction = fh.readLine()
-- We got an order, move!
if direction == "up" then
peripheral.call("left", "move", 1, false, false)
elseif direction == "down" then
peripheral.call("left", "move", 0, false, false)
else
print("ERR:/var/move: invalid")
end
-- Errors?
if rv == false then
print("ERR: " .. emsg)
rednet.broadcast("done")
fh.close()
end
end
-- Wait for a new order.
while true do
print("Waiting for new order...")
id, msg = rednet.receive()
print("recv: " .. id .. ": " .. msg)
-- Check if this is what we want.
if id == 4 then
if msg == "up" or msg == "down" then
print("recv order: " .. msg)
fh = fs.open("/var/move", "w")
fh.writeLine(msg)
fh.close()
print("write: " .. msg .. " >> /var/move")
os.reboot()
else
print("err: invalid order")
end
else
print("err: invalid controller")
end
end
This script is naturally called 'startup'.
Here's the issue. The script works fine, however once the Elevator is put in motion, the computer doesn't reboot anymore. It goes about 2 steps in the direction it's meant to go (meaning it has rebooted successfully at least once), and then it has to be right clicked to work.
Is this a bug or have I missed something really obvious?