Advertisement
Guest User

startup

a guest
Sep 29th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. os.loadAPI("ocs/apis/sensor")
  2.  
  3. local ss = sensor.wrap('sensor_1')
  4. local modem = peripheral.wrap("right")
  5.  
  6. --Splits input comma delimited string to table
  7. --of component strings
  8. function split(inputStr, sep)
  9.  if sep == nil then
  10.   sep = "%,"
  11.  end
  12.  local t={} ; i=1
  13.  for str in string.gmatch(inputStr, "([^"..sep.."]+)") do
  14.   t[i] = str
  15.   i = i + 1
  16.  end
  17.  return t
  18. end
  19.  
  20. --Checks sensor for lvl x blocks, returns table
  21. --of coords
  22. function getCoordList()
  23.  local targets = ss.getTargets()
  24.  local targetLoc = {}
  25.  --split each sensor reading and check for correct
  26.  --lvl and add to new table if true, return table
  27.  for k, v in pairs(targets) do
  28.   local coords = split(k)
  29.   local coord2 = coords[2]
  30.   if coord2 == "2" then --defines lvl
  31.      table.insert(targetLoc,k)
  32.   end
  33.  end
  34.  return(targetLoc)
  35. end
  36.  
  37. --Check table for element returns boolean
  38. function tableContains(table, element)
  39.  for _, value in pairs(table) do
  40.    if value == element then
  41.     return true
  42.    end
  43.  end
  44.  return false
  45. end
  46.  
  47. local masterList = getCoordList()
  48.  
  49. while true do
  50.  term.clear()
  51.  term.setCursorPos(1,1)
  52.  local compList = getCoordList()
  53.  local changeList = {}
  54.  print("# of Blocks: "..#compList) --return # of elements
  55.  
  56.   for k, v in pairs(compList) do
  57. --  if tableContains(masterList, v) then
  58.    print(v)
  59. --  else
  60. --   print(v.."CHANGED")
  61. --   table.insert(changeList,v)
  62. --   rednet.open(modem)
  63. --   local sV = split(v)
  64. --   local ssV = textutils.serialize(sV)
  65. --   rednet.send(118, ssV, "prot")
  66. --   rednet.close(modem)
  67. --  end
  68. end
  69.  
  70.  
  71. -- for k, v in pairs(changeList) do
  72. --  print(v.getTargetDetails())
  73. -- end
  74.  sleep(3)
  75.  
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement