Advertisement
Marlingaming

Station Main Computer Script

Dec 2nd, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. --this script acts as a central computer for a Rail Station, and gives Information relating to all connected Lines to the Directed Monitor
  2. --StationName,LineName,Protocol,Returning/Leaving, Arrived
  3. local Line1 = {'n','n',0,false,false}
  4. local Line2 = false
  5. local Line3 = false
  6. local Line4 = false
  7. local StationProtocol = 0
  8. local ModemSide = 'top'
  9. local MonitorID = false
  10.  
  11. term.clear()
  12. print("starting")
  13. print("Gathering Data")
  14. print("Checking Stations")
  15. Line1[4] = GetPlatformState(1)
  16. if Line2 != false then
  17. Line2[4] = GetPlatformState(2)
  18. end
  19. if Line3 != false then
  20. Line3[4] = GetPlatformState(3)
  21. end
  22. if Line4 != false then
  23. Line4[4] = GetPlatformState(4)
  24. end
  25. DisplayConnections()
  26. Loop()
  27.  
  28.  
  29. local function GetPlatformState(Platform)
  30. if ModemSide == 'n' then
  31. print("Failed to find Modem, please make sure to add what side it is on")
  32. else
  33. rednet.open(ModemSide)
  34. rednet.broadcast(Platform,StationProtocol)
  35. repeat
  36. local protocol, message, id = rednet.receive(StationProtocol..Platform)
  37. until protocol == StationProtocol..Platform
  38. if message == "Arrived"
  39. return(true)
  40. elseif message == "Departed"
  41. return(false)
  42. end
  43. end
  44. end
  45.  
  46. local function DisplayConnections()
  47. if MonitorID == false then
  48. print("Failed to find Monitor")
  49. else
  50. local Monitor = peripheral.wrap(MonitorID)
  51. Monitor.clear()
  52. Monitor.setCursorPos(1,1)
  53. Monitor.print("Station Name -- Platform -- Train Status")
  54. if Line1[4] == true then
  55. print(Line1[0].." -- 1 -- Arrived")
  56. elseif Line1[3] == true then
  57. print(Line1[0].." -- 1 -- Returning")
  58. elseif Line1[3] == false then
  59. print(Line1[0].." -- 1 -- Left")
  60. end
  61. if Line2 == false then
  62. print("----CANCELED----")
  63. elseif Line2[4] == true then
  64. print(Line2[0].." -- 2 -- Arrived")
  65. elseif Line2[3] == true then
  66. print(Line2[0].." -- 2 -- Returning")
  67. elseif Line2[3] == false then
  68. print(Line2[0].." -- 2 -- Left")
  69. end
  70. if Line3 == false then
  71. print("----CANCELED----")
  72. elseif Line3[4] == true then
  73. print(Line3[0].." -- 3 -- Arrived")
  74. elseif Line3[3] == true then
  75. print(Line3[0].." -- 3 -- Returning")
  76. elseif Line3[3] == false then
  77. print(Line3[0].." -- 3 -- Left")
  78. end
  79. if Line4 == false then
  80. print("----CANCELED----")
  81. elseif Line4[4] == true then
  82. print(Line4[0].." -- 4 -- Arrived")
  83. elseif Line4[3] == true then
  84. print(Line4[0].." -- 4 -- Returning")
  85. elseif Line4[3] == false then
  86. print(Line4[0].." -- 4 -- Left")
  87. end
  88. end
  89. end
  90.  
  91. function Loop()
  92. DisplayConnections()
  93. repeat
  94. local message, id, protocol = rednet.recieve()
  95. until message == "Arrived" or message == "Departed" or message == "Returning" or message == "Leaving"
  96. if protocol == StationProtocol
  97. print("recieved Message")
  98. elseif protocol == StationProtocol..1
  99. getPlatformState(1)
  100. elseif protocol == StationProtocol..2
  101. getPlatformState(2)
  102. elseif protocol == StationProtocol..3
  103. getPlatformState(3)
  104. elseif protocol == StationProtocol..4
  105. getPlatformState(4)
  106. end
  107. Loop()
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement