Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --this script acts as a central computer for a Rail Station, and gives Information relating to all connected Lines to the Directed Monitor
- --StationName,LineName,Protocol,Returning/Leaving, Arrived
- local Line1 = {'n','n',0,false,false}
- local Line2 = false
- local Line3 = false
- local Line4 = false
- local StationProtocol = 0
- local ModemSide = 'top'
- local MonitorID = false
- term.clear()
- print("starting")
- print("Gathering Data")
- print("Checking Stations")
- Line1[4] = GetPlatformState(1)
- if Line2 != false then
- Line2[4] = GetPlatformState(2)
- end
- if Line3 != false then
- Line3[4] = GetPlatformState(3)
- end
- if Line4 != false then
- Line4[4] = GetPlatformState(4)
- end
- DisplayConnections()
- Loop()
- local function GetPlatformState(Platform)
- if ModemSide == 'n' then
- print("Failed to find Modem, please make sure to add what side it is on")
- else
- rednet.open(ModemSide)
- rednet.broadcast(Platform,StationProtocol)
- repeat
- local protocol, message, id = rednet.receive(StationProtocol..Platform)
- until protocol == StationProtocol..Platform
- if message == "Arrived"
- return(true)
- elseif message == "Departed"
- return(false)
- end
- end
- end
- local function DisplayConnections()
- if MonitorID == false then
- print("Failed to find Monitor")
- else
- local Monitor = peripheral.wrap(MonitorID)
- Monitor.clear()
- Monitor.setCursorPos(1,1)
- Monitor.print("Station Name -- Platform -- Train Status")
- if Line1[4] == true then
- print(Line1[0].." -- 1 -- Arrived")
- elseif Line1[3] == true then
- print(Line1[0].." -- 1 -- Returning")
- elseif Line1[3] == false then
- print(Line1[0].." -- 1 -- Left")
- end
- if Line2 == false then
- print("----CANCELED----")
- elseif Line2[4] == true then
- print(Line2[0].." -- 2 -- Arrived")
- elseif Line2[3] == true then
- print(Line2[0].." -- 2 -- Returning")
- elseif Line2[3] == false then
- print(Line2[0].." -- 2 -- Left")
- end
- if Line3 == false then
- print("----CANCELED----")
- elseif Line3[4] == true then
- print(Line3[0].." -- 3 -- Arrived")
- elseif Line3[3] == true then
- print(Line3[0].." -- 3 -- Returning")
- elseif Line3[3] == false then
- print(Line3[0].." -- 3 -- Left")
- end
- if Line4 == false then
- print("----CANCELED----")
- elseif Line4[4] == true then
- print(Line4[0].." -- 4 -- Arrived")
- elseif Line4[3] == true then
- print(Line4[0].." -- 4 -- Returning")
- elseif Line4[3] == false then
- print(Line4[0].." -- 4 -- Left")
- end
- end
- end
- function Loop()
- DisplayConnections()
- repeat
- local message, id, protocol = rednet.recieve()
- until message == "Arrived" or message == "Departed" or message == "Returning" or message == "Leaving"
- if protocol == StationProtocol
- print("recieved Message")
- elseif protocol == StationProtocol..1
- getPlatformState(1)
- elseif protocol == StationProtocol..2
- getPlatformState(2)
- elseif protocol == StationProtocol..3
- getPlatformState(3)
- elseif protocol == StationProtocol..4
- getPlatformState(4)
- end
- Loop()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement