Marlingaming

Train Journey Setup

Sep 9th, 2021 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. --this program creates a Virtual Path and directions for any inserted Tablets, for the automation of trains.
  2. local page = "Menu"
  3. PathSteps = []
  4. PathDir = []
  5. local JourneySetup = 0
  6. local CurrentStation = ["Current Station","Left Track","Right Track"]
  7. TrainID = nil
  8. local Destination = nil
  9. Owner = "n"
  10. GridX = 0
  11. GridY = 0
  12. TrainX = 0
  13. TrainY = 0
  14. local SetPriority = 1
  15. Settings_PathMethod = "Detailed" --Detailed or Grid, grid makes it so it goess off of which one brings it closest to its destination while detail uses the exact names of stations and Switch positions. grid is best for newer lines while Detailed is best for older and more developed lines.
  16. start()
  17.  
  18. function start()
  19. MenuManager()
  20. end
  21.  
  22. function MenuManager()
  23. print("please Enter Train ID")
  24. local event, key = os.pullEvent("key")
  25. until TrainID ~= nil do
  26. local input = read()
  27. if event, key == keys.getName("enter") then
  28. TrainID = input
  29. end
  30. end
  31. print("Please Enter Station code of Destination")
  32. until Destination ~= nil do
  33. local input = read()
  34. if event, key == keys.getName("enter") then
  35. Destination = input
  36. end
  37. end
  38. CreateJourney()
  39. end
  40.  
  41. function CreateJourney()
  42. local StationsFile = fs.open("AvStations","r")
  43. local i = 1
  44. local I = 1
  45. until JourneySetup == 1 do
  46. if StationsFile.readLine(i) == CurrentStation[2] or StationsFile.readLine(i) == CurrentStation[3] then
  47. if StationsFile.readLine(i) == CurrentStation[2] then
  48. PathDir[1] = 0
  49. else if StationsFile.readLine(i) == CurrentStation[3] then
  50. PathDir[1] = 1
  51. end
  52. JourneySetup == 1
  53. else if StationsFile.readLine(i+1) == PathSteps[I-1] then
  54. PathSteps[I] = StationFile.readLine(i)
  55. PathDir[I] = 0
  56. I = I+1
  57. else if StationsFile.readLine(i+2) == PathSteps[I-1] then
  58. PathSteps[I] = StationFile.readLine(i)
  59. PathDir[I] = 1
  60. I = I+1
  61. end
  62. if i >= #StationsFile.list() then
  63. i=1
  64. else
  65. i=i+3
  66. end
  67. end
  68. StationsFile.close()
  69. local file = fs.open("StationCords","r")
  70. i = 1
  71. local GridCord = nil
  72. until JourneySetup == 2 do
  73. if file.readLine(i-1) == Destination then
  74. GridCord = file.readLine(i)
  75. JourneySetup == 1
  76. end
  77. if i >= #StationsFile.list() then
  78. i=1
  79. else
  80. i=i+2
  81. end
  82. end
  83. file.close()
  84. GridX = GridCord[1]
  85. GridY = GridCord[2]
  86. GeneratePathData()
  87. end
  88.  
  89. function GeneratePathData()
  90. local file = fs.open("PathData_"..TrainID,"w")
  91. for i = #PathSteps, #PathSteps do
  92. file.writeline(PathDir[i]) --switch direction
  93. file.writeline(PathSteps[i]) --station
  94. i = i-1
  95. end
  96. file.close()
  97. file = fs.open("JourneySettings_"..TrainID,"w")
  98. file.writeLine("Path File = PathData_"..TrainID)
  99. file.writeLine("Track Priority = "..SetPriority)
  100. file.writeLine("TrainOwner = "..Owner)
  101. file.writeLine("Send off Date = "..)
  102. file.writeLine("Destination_Grid_X = "..GridX)
  103. file.writeLine("Destination_Grid_Y = "..GridY)
  104. file.writeLine("TravelMethod = "..Settings_PathMethod)
  105. file.close()
  106. file = fs.open("TrainData_"..TrainID,"w")
  107. file.write("["..TrainX..","..TrainY.."]"
  108. file.close()
  109. UploadPath()
  110. end
  111.  
  112.  
  113.  
  114. function UploadPath()
  115. peripheral.wrap("left").open
  116. local DownloadPath = nil
  117. while true do
  118. if isDiskPresent() == true then
  119. DownloadPath = getMountPath()
  120. end
  121. end
  122. fs.move("PathData_"..TrainID,DownloadPath)
  123. fs.move("JourneySettings_"..TrainID,DownloadPath)
  124. fs.move("TrainData_"..TrainID,DownloadPath)
  125. sleep(10)
  126. os.reboot()
  127. end
Add Comment
Please, Sign In to add comment