Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --this program creates a Virtual Path and directions for any inserted Tablets, for the automation of trains.
- local page = "Menu"
- PathSteps = []
- PathDir = []
- local JourneySetup = 0
- local CurrentStation = ["Current Station","Left Track","Right Track"]
- TrainID = nil
- local Destination = nil
- Owner = "n"
- GridX = 0
- GridY = 0
- TrainX = 0
- TrainY = 0
- local SetPriority = 1
- 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.
- start()
- function start()
- MenuManager()
- end
- function MenuManager()
- print("please Enter Train ID")
- local event, key = os.pullEvent("key")
- until TrainID ~= nil do
- local input = read()
- if event, key == keys.getName("enter") then
- TrainID = input
- end
- end
- print("Please Enter Station code of Destination")
- until Destination ~= nil do
- local input = read()
- if event, key == keys.getName("enter") then
- Destination = input
- end
- end
- CreateJourney()
- end
- function CreateJourney()
- local StationsFile = fs.open("AvStations","r")
- local i = 1
- local I = 1
- until JourneySetup == 1 do
- if StationsFile.readLine(i) == CurrentStation[2] or StationsFile.readLine(i) == CurrentStation[3] then
- if StationsFile.readLine(i) == CurrentStation[2] then
- PathDir[1] = 0
- else if StationsFile.readLine(i) == CurrentStation[3] then
- PathDir[1] = 1
- end
- JourneySetup == 1
- else if StationsFile.readLine(i+1) == PathSteps[I-1] then
- PathSteps[I] = StationFile.readLine(i)
- PathDir[I] = 0
- I = I+1
- else if StationsFile.readLine(i+2) == PathSteps[I-1] then
- PathSteps[I] = StationFile.readLine(i)
- PathDir[I] = 1
- I = I+1
- end
- if i >= #StationsFile.list() then
- i=1
- else
- i=i+3
- end
- end
- StationsFile.close()
- local file = fs.open("StationCords","r")
- i = 1
- local GridCord = nil
- until JourneySetup == 2 do
- if file.readLine(i-1) == Destination then
- GridCord = file.readLine(i)
- JourneySetup == 1
- end
- if i >= #StationsFile.list() then
- i=1
- else
- i=i+2
- end
- end
- file.close()
- GridX = GridCord[1]
- GridY = GridCord[2]
- GeneratePathData()
- end
- function GeneratePathData()
- local file = fs.open("PathData_"..TrainID,"w")
- for i = #PathSteps, #PathSteps do
- file.writeline(PathDir[i]) --switch direction
- file.writeline(PathSteps[i]) --station
- i = i-1
- end
- file.close()
- file = fs.open("JourneySettings_"..TrainID,"w")
- file.writeLine("Path File = PathData_"..TrainID)
- file.writeLine("Track Priority = "..SetPriority)
- file.writeLine("TrainOwner = "..Owner)
- file.writeLine("Send off Date = "..)
- file.writeLine("Destination_Grid_X = "..GridX)
- file.writeLine("Destination_Grid_Y = "..GridY)
- file.writeLine("TravelMethod = "..Settings_PathMethod)
- file.close()
- file = fs.open("TrainData_"..TrainID,"w")
- file.write("["..TrainX..","..TrainY.."]"
- file.close()
- UploadPath()
- end
- function UploadPath()
- peripheral.wrap("left").open
- local DownloadPath = nil
- while true do
- if isDiskPresent() == true then
- DownloadPath = getMountPath()
- end
- end
- fs.move("PathData_"..TrainID,DownloadPath)
- fs.move("JourneySettings_"..TrainID,DownloadPath)
- fs.move("TrainData_"..TrainID,DownloadPath)
- sleep(10)
- os.reboot()
- end
Add Comment
Please, Sign In to add comment