Advertisement
Shuudoushi

trains

Feb 8th, 2015
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.80 KB | None | 0 0
  1. local component = require("component")
  2. local term = require("term")
  3. local sides = require("sides")
  4. local colors = require("colors")
  5. local rs = component.redstone
  6. local io = require("io")
  7. local fs = require("filesystem")
  8.  
  9. local running = true
  10. local numberOfTrains = 0
  11. local isParked = false
  12. local isTrain1 = false
  13. local isTrain2 = false
  14. local isTrain3 = false
  15. local isShuttingDown = false
  16.  
  17.  
  18. local function initSetup()
  19.  
  20.   -- Test to see if isParked is all ready on
  21.  
  22.   --rs.setBundledOutput(sides.north, colors.orange, 255)
  23.  
  24.   if rs.getBundledInput(sides.north, colors.gray) == true then
  25.       rs.setBundledOutput(sides.north, colors.brown+colors.pink, 0)
  26.  
  27.      --isParked = true
  28.   end
  29.  
  30.   --if rs.getBundledInput(sides.north, colors.pink) == true then
  31.   --  isTrain1 = true
  32.   --elseif rs.getBundledInput(sides.north, colors.pink) == false then
  33.   --  isTrain1 = false
  34.   --end
  35.  
  36. end
  37.  
  38. local function setupCheck()
  39.     if fs.exists("/tmp/cookie.txt") == false then
  40.         initSetup()
  41.         c = io.open("/tmp/cookie.txt", "w")
  42.          c:write("This is a cookie.")
  43.           c:close()
  44.     else
  45.         nil
  46.     end
  47. end
  48.  
  49. local function ui()
  50.   term.clear()
  51.   term.setCursor(10,3)
  52.   term.write("Main Menu")
  53.   term.setCursor(10,5)
  54.   term.write("1. Park Train on : " ..tostring(isParked))
  55.   term.setCursor(10,7)
  56.   term.write("2. Train 1 is running : " ..tostring(isTrain1))
  57.   term.setCursor(10,8)
  58.   term.write("3. Train 2 is running : " ..tostring(isTrain2))
  59.   term.setCursor(10,9)
  60.   term.write("4. Train 3 is running : " ..tostring(isTrain3))
  61.   term.setCursor(10, 11)
  62.   term.write("Shutting Down Train : "..tostring(isShuttingDown))  
  63.   term.setCursor(10, 15)
  64.   term.write("Q Quit or Exit")
  65.   term.setCursor(10,16)
  66. end
  67.  
  68. local function input()
  69.   answer = term.read()
  70.   answer= string.gsub(answer, "\n", "")
  71.  
  72.   if answer == "1" then
  73.  
  74.       if isParked == false then
  75.         rs.setBundledOutput(sides.north, colors.white, 255)
  76.       elseif isParked == true then
  77.         rs.setBundledOutput(sides.north, colors.white, 0)
  78.       end
  79.  
  80.       if isParked == true then
  81.       isParked = false
  82.       isShuttingDown = true
  83.       elseif isParked == false then
  84.       isShuttingDown = false
  85.       isParked = true
  86.       end
  87.  
  88.  
  89.   end
  90.   if answer == "2" then
  91.  
  92.     if isTrain1 == false then
  93.       rs.setBundledOutput(sides.north, colors.pink, 255)
  94.       rs.setBundledOutput(sides.north, colors.brown, 0)
  95.     elseif isTrain1 == true then
  96.       rs.setBundledOutput(sides.north, colors.pink, 0)
  97.       rs.setBundledOutput(sides.north, colors.brown, 255)
  98.     end
  99.  
  100.     if isTrain1 == true then
  101.       isTrain1 = false
  102.     elseif isTrain1 == false then
  103.       isTrain1 = true
  104.       end    
  105.   end
  106.   if answer == "Q" or answer == "q" then
  107.     running = false
  108.   end
  109. end
  110.  
  111. while running do
  112.     setupCheck()
  113.   --chStatus()
  114.   ui()
  115.   input()
  116. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement