Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ocs/apis/sensor")
- local ss = sensor.wrap('sensor_1')
- local modem = peripheral.wrap("right")
- --Splits input comma delimited string to table
- --of component strings
- function split(inputStr, sep)
- if sep == nil then
- sep = "%,"
- end
- local t={} ; i=1
- for str in string.gmatch(inputStr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- return t
- end
- --Checks sensor for lvl x blocks, returns table
- --of coords
- function getCoordList()
- local targets = ss.getTargets()
- local targetLoc = {}
- --split each sensor reading and check for correct
- --lvl and add to new table if true, return table
- for k, v in pairs(targets) do
- local coords = split(k)
- local coord2 = coords[2]
- if coord2 == "2" then --defines lvl
- table.insert(targetLoc,k)
- end
- end
- return(targetLoc)
- end
- --Check table for element returns boolean
- function tableContains(table, element)
- for _, value in pairs(table) do
- if value == element then
- return true
- end
- end
- return false
- end
- local masterList = getCoordList()
- while true do
- term.clear()
- term.setCursorPos(1,1)
- local compList = getCoordList()
- local changeList = {}
- print("# of Blocks: "..#compList) --return # of elements
- for k, v in pairs(compList) do
- -- if tableContains(masterList, v) then
- print(v)
- -- else
- -- print(v.."CHANGED")
- -- table.insert(changeList,v)
- -- rednet.open(modem)
- -- local sV = split(v)
- -- local ssV = textutils.serialize(sV)
- -- rednet.send(118, ssV, "prot")
- -- rednet.close(modem)
- -- end
- end
- -- for k, v in pairs(changeList) do
- -- print(v.getTargetDetails())
- -- end
- sleep(3)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement