Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Station name should be saved in "station.txt" file!
- local TRAIN_COMM_PORT = 101
- local modem = peripheral.wrap("left")
- if modem.isOpen(TRAIN_COMM_PORT) then
- modem.close(TRAIN_COMM_PORT)
- end
- modem.open(TRAIN_COMM_PORT)
- local function getStationName()
- local sfh = fs.open("station.txt", "r")
- local station_name = sfh.readLine()
- sfh.close()
- return station_name
- end
- while true do
- local event, modemSide, senderChannel,
- replyChannel, message, senderDistance = os.pullEvent("modem_message")
- local this_station_name = getStationName()
- if message == this_station_name then
- if replyChannel == 102 then -- This station is where the train is coming from
- redstone.setAnalogOutput("right", 10)
- redstone.setAnalogOutput("back", 0)
- redstone.setAnalogOutput("front", 0)
- print("Sending train to target station...")
- sleep(20)
- redstone.setAnalogOutput("right", 0)
- elseif replyChannel == 103 then -- This station is the target, and train is coming from behind the computer
- redstone.setAnalogOutput("right", 0)
- redstone.setAnalogOutput("front", 10)
- print("Receiving train from up the line...")
- sleep(40)
- redstone.setAnalogOutput("right", 10)
- redstone.setAnalogOutput("front", 0)
- elseif replyChannel == 104 then -- This station is the target, and train is coming from in front of the computer
- redstone.setAnalogOutput("right", 0)
- redstone.setAnalogOutput("back", 10)
- print("Receiving train from down the line...")
- sleep(40)
- redstone.setAnalogOutput("right", 10)
- redstone.setAnalogOutput("back", 0)
- end
- elseif not replyChannel == 102 then
- redstone.setAnalogOutput("right", 10)
- redstone.setAnalogOutput("back", 0)
- redstone.setAnalogOutput("front", 0)
- print("This station is not the train's target, letting it pass...")
- end
- end
Add Comment
Please, Sign In to add comment