Advertisement
Necrotico

CC Train System - Controller

Feb 12th, 2022
1,370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.79 KB | None | 0 0
  1. -- For use with a pocket computer!
  2.  
  3. -- Command Structure: "controller direction start_station_name end_station_name"
  4. -- Example Usage: "controller up my_cool_station my_even_cooler_station"
  5.  
  6. local TRAIN_COMM_PORT = 101
  7.  
  8. local modem = peripheral.wrap("back")
  9.  
  10. local args = {...}
  11.  
  12. local direction = args[1]
  13. local start_station_name = args[2]
  14. local end_station_name = args[3]
  15.  
  16. if (not direction == "up") and (not direction == "down") then
  17.     print("ERROR: INVALID DIRECTION! (Must be 'up' or 'down')")
  18.     shell.exit()
  19. end
  20.  
  21. local direction_port = 103
  22. if direction == "up" then
  23.     direction_port = 104
  24. end
  25.  
  26. modem.transmit(TRAIN_COMM_PORT, 102, start_station_name)
  27.  
  28. sleep(15)
  29.  
  30. while true do
  31.     modem.transmit(TRAIN_COMM_PORT, direction_port, end_station_name)
  32.     sleep(1)
  33. end
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement