Guest User

control

a guest
May 17th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.02 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2.  
  3. running = true
  4.  
  5. if not fs.exists(".cSide") then
  6.  write("Cable side: ")
  7.  B = read()
  8.  A = fs.open(".cSide", "w")
  9.  A.write(B)
  10.  A.close()
  11.  cSide = B
  12. else
  13.  A = fs.open(".cSide", "r")
  14.  B = A.readAll()
  15.  A.close()
  16.  for i,v in pairs(rs.getSides()) do
  17.   if B~=v then
  18.  
  19.   else
  20.    cSide = B
  21.    break
  22.   end
  23.   cSide = "back"
  24.  end
  25. end
  26.  
  27. states = {}
  28. for i=1, 17 do
  29.   states[i] = "Offline"
  30. end
  31.  
  32. function draw()
  33.  term.clear()
  34.  D = 1
  35.   for i=1, 17 do
  36.    if i < 17 then    
  37.     paintutils.drawLine(1, i+1, 51, i+1, D)
  38.     D = 2^i
  39.    end
  40.    
  41.     if states[i] == "Online" then term.setTextColor(colors.lime) else term.setTextColor(colors.red) end
  42.     term.setCursorPos(2, i+1)
  43.       if i~=17 then
  44.        if i==15 and states[15]=="Offline" then
  45.         term.setTextColour(colors.white)
  46.        elseif i==6 and states[6]=="Online" then
  47.         term.setTextColour(colors.blue)
  48.        end
  49.         print("Cable "..tostring(i)..": "..states[i])
  50.       elseif i==17 then
  51.         print("All Cable's: "..states[i])
  52.     end
  53.   end
  54. end
  55.  
  56. while running do
  57. local sCount = 0
  58.  for i=1,16 do
  59.   if states[i]=="Online" then sCount = sCount + 1
  60.   else
  61.   end
  62.  end
  63.  if sCount ~=16 then states[17]="Offline"
  64.  elseif sCount==16 then states[17]="Online"
  65.  end
  66.   draw()
  67.   _, key, y, x = os.pullEvent("mouse_click")
  68.   -- Yes, I know x and y are reverse
  69.   if _ or key then
  70.   if x ~= nil then
  71.    x = x - 1
  72.   end
  73.   end
  74.  if x ~= nil then
  75.   if x >=1 and x <= 16 then
  76.     if states[x] == "Online" then states[x] = "Offline"
  77.     elseif states[x] == "Offline" then states[x] = "Online" end
  78.   elseif x == 17 then
  79.     if states[x] == "Online" then B = "Offline" states[x] = "Offline"
  80.     elseif states[x] == "Offline" then B = "Online" states[x] = "Online" end  
  81.     for i=1,17 do
  82.      states[i] = B
  83.    
  84.     end
  85.     draw()
  86.   end
  87.  end
  88.  
  89.   local color = 0
  90.   for i, v in pairs(states) do
  91.     if v == "Online" then
  92.       color = color + (2^(i-1))
  93.     end
  94.   end
  95.   rs.setBundledOutput(cSide, color)
  96. end
Advertisement
Add Comment
Please, Sign In to add comment