Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --this program wakes up the computer, and then communicates with any nearby trains for instructions
- StationID = "n"
- StationX = 0
- StationY = 0
- StationFace = "N"
- StationConnections = ["n","n"]
- DetectedMethod = nil
- local ContactedTrain = nil
- SwitchSet = 0
- local Target = nil
- start()
- function start()
- rednet.open("bottom")
- TrackManager()
- end
- function TrackManager()
- if SwitchSet == 0 then
- redstone.setOutput("back", off)
- else if SwitchSet == 1 then
- redstone.setOutput("back", on)
- end
- local id, message
- repeat
- id, message = rednet.receive()
- until message == "["..StationX..","..StationY.."]" or message == StationID
- if message == "["..StationX..","..StationY.."]" then
- DetectedMethod = "Grid"
- else if message == StationID then
- DetectedMethod = "Detail"
- end
- ContactedTrain = id
- TrainComms()
- end
- function TrainComms()
- rednet.send(ContactedTrain, "["..StationX..","..StationY.."]",2300)
- repeat
- id, message = rednet.receive()
- until id == ContactedTrain
- if message == Ready then
- rednet.send(ContactedTrain,"y",3450)
- repeat
- id, message = rednet.receive()
- until id == ContactedTrain
- Target = message
- SetupTracks()
- end
- end
- function SetupTracks()
- if DetectedMethod == "Grid" then
- local DesX = Target[1]
- local DesY = Target[2]
- if StationFace == "N" then
- if StationX > DesX then
- SwitchSet = 0
- else if StationX < DesX then
- SwitchSet = 1
- end
- else if StationFace == "East" then
- if StationY > DesY then
- SwitchSet = 0
- else if StationY < DesY then
- SwitchSet = 1
- end
- else if StationFace == "South" then
- if StationX > DesX then
- SwitchSet = 1
- else if StationX < DesX then
- SwitchSet = 0
- end
- else if StationFace == "West" then
- if StationY > DesY then
- SwitchSet = 0
- else if StationY < DesY then
- SwitchSet = 1
- end
- end
- else
- end
- repeat until redstone.getOutput("front") >= 1
- rednet.send(ContactedTrain,"Passed",3450)
- os.reboot()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement