Guest User

test

a guest
Feb 18th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  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.   _, inList = e.pull("effects_updated")
  41.  end
  42. end
  43.  
  44. function inputList()
  45.  m.broadcast(1, "nanomachines", "getTotalInputCount")
  46.  e.pull("updated_inputs")
  47.  for i=1, inputs do
  48.   num = tostring(i)
  49.   msg = "Input: "..num
  50.   print(msg.." registered")
  51.   Input(i)
  52.   Input(i)
  53.  end
  54. end
  55.  
  56. inputList()
  57.  
  58. function list()
  59.  clear()
  60.  x, y, length = 3, 3, 0
  61.  for i,v in pairs(inList) do
  62.   print(v)
  63.   printToMon(v, x + length, y)
  64.   x = x + 3 + length
  65.   length = string.len(v)
  66.   z, t = maxX - oX, maxY - oY
  67.   if x + length >= z then
  68.    y = y + 2
  69.    x = 3
  70.    length = 0
  71.   end
  72.  end
  73. end
  74.  
  75. function mainScreen()
  76.  list()
  77. end
  78.  
  79. while true do
  80.  mainScreen()
  81.  printToMon("x", 32, 32)
  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