jaypar

Untitled

Feb 18th, 2018 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. component = require("component")
  2. gpu = component.gpu
  3. e = require("event")
  4. m = component.modem
  5. string = require("string")
  6. term = require("term")
  7. table = require("table")
  8. c = false
  9. x, y, length, n, l = 3, 3, 0, 3, 3
  10. j = 1
  11.  
  12. m.open(2)
  13. m.broadcast(1, "nanomachines", "setResponsePort", 2)
  14. e.pull("modem_message")
  15.  
  16. maxX, maxY, oX, oY = term.getViewport()
  17. inList = {}
  18.  
  19. function clear()
  20.  gpu.fill(1, 1, maxX, maxY, " ")
  21. end
  22.  
  23. function printToMon(str, x, y)
  24.  gpu.set(x, y, str)
  25. end
  26.  
  27. function Input(num)
  28.  m.broadcast(1, "nanomachines", "getInput", num)
  29.  _, c, j = e.pull("msg_recieved")
  30.  if c == true then
  31.   m.broadcast(1, "nanomachines", "setInput", num, false)
  32.   print("Turning input "..num.." off")
  33.   e.pull("msg_recieved")
  34.  elseif c == false then
  35.   m.broadcast(1, "nanomachines", "setInput", num, true)
  36.   e.pull("msg_recieved")
  37.   print("Getting effects of input "..num.." now")
  38.   m.broadcast(1, "nanomachines", "getActiveEffects")
  39.   print("cont")
  40.   e.push("effects_table", inList)
  41.   _, inList = e.pull("effects_updated")
  42.  end
  43. end
  44.  
  45. function inputList()
  46.  m.broadcast(1, "nanomachines", "getTotalInputCount")
  47.  e.pull("updated_inputs")
  48.  for i=1, inputs do
  49.   num = tostring(i)
  50.   msg = "Input: "..num
  51.   print(msg.." registered")
  52.   Input(i)
  53.   Input(i)
  54.  end
  55. end
  56.  
  57. inputList()
  58.  
  59. function list()
  60.  clear()
  61.  x, y, length = 3, 3, 0
  62.  for i,v in pairs(inList) do
  63.   z, t = maxX - oX, maxY - oY
  64.   if x + string.len(v) >= z then
  65.    y = y + 2
  66.    x = 3
  67.    length = 0
  68.   end
  69.   printToMon(v, x + length, y)
  70.   x = x + 3 + length
  71.   length = string.len(v)
  72.  end
  73. end
  74.  
  75. function mainScreen()
  76.  list()
  77. end
  78.  
  79. while true do
  80.  mainScreen()
  81.  printToMon("x", 3, 3)
  82.  _, s, x, y, b, user = e.pull("touch")
  83.  printToMon("t", x, y)
  84.  for i,v in pairs(inList) do
  85.   if l <= x and string.len(v) >= x and n == y then
  86.    Input(i)
  87.   end
  88.   length = string.len(v)
  89.   l = l + 3 + length
  90.   if l >= maxX then
  91.    l = 3
  92.    n = n + 2
  93.   end
  94.  end
  95. end
Advertisement
Add Comment
Please, Sign In to add comment