Posted 06 November 2013 - 06:40 AM
I am going to make a station which, when an empty cart comes, the computer will automatically sleep for 60 seconds, with a message printed to the monitor every 10 seconds. After 60 seconds, the computer should be able to emit a redstone signal so that the cart will depart.
In the above picture, you can see there is two computers, labeled as computer A and B. When an empty cart arrives, there will be a redstone signal to the front of the computer A. Then, computer A will transmit a message through the wireless modem attached to its back to computer B. The message is Display. Computer B will listen for the message. Then, computer B will output the sentence "x seconds left to departure.". The sentence will be outputted to the monitor attached to its back and outputted at 60, 50, 40, 30, 20, 10 and 0 second(s) left. After outputting, computer B will send a message to computer A. The message is 0. When computer A receives the message, computer A sends a redstone signal to its left side, which is the thing in the lower left corner in the above picture.
Problem:
Both computers have NO communication between each other. Computer B cannot receive any message from computer A (tested by echo checking e.g. outputting message to console), thus computer B cannot send any message to computer A also.
Program codes:
For computer A (program name is depart)
For computer B (program name is departout)
Thank you very much for helping.
In the above picture, you can see there is two computers, labeled as computer A and B. When an empty cart arrives, there will be a redstone signal to the front of the computer A. Then, computer A will transmit a message through the wireless modem attached to its back to computer B. The message is Display. Computer B will listen for the message. Then, computer B will output the sentence "x seconds left to departure.". The sentence will be outputted to the monitor attached to its back and outputted at 60, 50, 40, 30, 20, 10 and 0 second(s) left. After outputting, computer B will send a message to computer A. The message is 0. When computer A receives the message, computer A sends a redstone signal to its left side, which is the thing in the lower left corner in the above picture.
Problem:
Both computers have NO communication between each other. Computer B cannot receive any message from computer A (tested by echo checking e.g. outputting message to console), thus computer B cannot send any message to computer A also.
Program codes:
For computer A (program name is depart)
local modem = perihperal.wrap("back")
modem.open(1)
function listen()
modem.transmit(1, 1, "Display")
local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
if message == "0" then
redstone.setOutput("left", true)
os.sleep(0.5)
redstone.setOutput("left", false)
end
end
function execute()
if redstone.getInput("front") == true then
listen()
end
while true do
r = os.pullEvent()
if r == "Redstone" then
if redstone.getInput("front") == true then
listen()
end
end
end
end
function waitForEsc()
while true do
local e, key = os.pullEvent("key")
if key ~= 1 then
return true
end
end
end
parallel.waitForAny(function() execute() end, function() waitForEsc() end)
For computer B (program name is departout)
local modem = peripheral.wrap("right")
local monitor = peripheral.wrap("back")
modem.open(1)
function out(count)
monitor.write(count, "seconds left to departure.")
end
function rstick()
local counter = 60
while counter > 0 do
out(count)
os.sleep(10)
counter = counter - 10
end
modem.transmit(1, 1, "0")
end
function execute()
while true do
local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
if message = "Display" then
rstick()
end
end
end
function waitForEsc()
while true do
local e, key = os.pullEvent("key")
if key ~= 1 then
return true
end
end
end
parallel.waitForAny(function() execute() end, function() waitForEsc() end)
Thank you very much for helping.