Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --this program is for the tablet in control of a train.
- NextStation = nil
- CStation = nil
- NextX = nil
- NextY = nil
- DestinationX = nil
- DestinationY = nil
- TrainX = nil
- TrainY = nil
- TrainID = nil
- PathMethod = nil
- Wait = 0
- ContactedStation_ID = nil
- Target =
- start()
- function start()
- local Settings = fs.open("TrainData","r")
- local TrainCords = readLine(1)
- TrainX = TrainCords[1]
- TrainY = TrainCords[2]
- Settings.close()
- local Travel = fs.open("JourneySettings","r")
- PathMethod = Travel.readLine(7)
- DestinationX = Travel.readLine(5)
- DestinationY = Travel.readLine(6)
- Travel.close()
- TravelManager()
- end
- function TravelManager()
- while true do
- if PathMethod == "Grid" then
- GridControl()
- else if PathMethod == "Detail" then
- DetailControl()
- end
- end
- end
- function GridControl()
- if Wait == 15 then
- Wait = 0
- SwitchContact()
- else
- Wait = Wait + 1
- end
- end
- function DetailControl()
- if Wait == 15 then
- Wait = 0
- SwitchContact()
- else
- Wait = Wait + 1
- end
- end
- function SwitchContact()
- rednet.open("back")
- if PathMethod == "Grid" then
- rednet.broadcast("["..TrainX..","..TrainY.."]", 3632)
- else if PathMethod == "Detail" then
- rednet.broadcast(NextStation,3632)
- end
- local id, message = rednet.receive(2300,5)
- if message == [TrainX,TrainY] or message == CStation then
- ContactedStation_ID = id
- SwitchController()
- end
- end
- function SwitchController()
- rednet.open("back")
- rednet.send(ContactedStation_ID, "Ready", 3450)
- local id, message
- repeat
- id, message = rednet.receive()
- until id == ContactedStation_ID
- if message == "n" then
- else if message == "y" then
- if PathMethod == "Grid" then
- Target = [DestinationX,DestinationY]
- else if PathMethod == "Detail" then
- Target = NextStation
- end
- rednet.send(ContactedStation_ID, Target, 3450)
- repeat
- id, message = rednet.receive()
- until id == ContactedStation_ID
- if message == "Ready" then
- repeat
- id, message = rednet.receive()
- until id == ContactedStation_ID
- if message == "Passed" then
- TrainX = NextX
- TrainY = NextY
- ChangeNext()
- end
- end
- end
- end
- function ChangeNext()
- if PathMethod == "Grid" then
- local h = fs.open("TrainData","a")
- h.setCursorPos(1,1)
- h.clearLine()
- h.writeLine("["..NextX..","..NextY.."]"
- h.close()
- if TrainX > DestinationX then
- NextX = TrainX-1
- else if TrainX < DestinationX then
- NextX = TrainX+1
- else
- NextX = TrainX
- end
- if TrainY > DestinationY then
- NextY = TrainY-1
- else if TrainY < DestinationY then
- NextY = TrainY+1
- else
- NextY = TrainY
- end
- local t = fs.open("JourneySettings","a")
- t.setCursorPos(1,5)
- t.clearLine()
- t.writeLine(NextX)
- t.setCursorPos(1,6)
- t.clearLine()
- t.writeLine(NextY)
- t.close()
- else PathMethod =="Detail" then
- local file = fs.open("PathData","r")
- for i = 1, #file.list() do
- if file.readLine(i) == NextStation then
- NextStation = file.readLine(i+1)
- end
- end
- file.close()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement