Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args={...}
- if #args==0 then
- error("required arguments: monitorName")
- end
- mName=args[1]
- monitor=peripheral.wrap("right")
- monitor.setTextScale(1)
- monitor.clear()
- function len(txt)
- return #txt
- end
- rednet.open("left")
- texts={}
- function rewrite()
- lines={}
- c=0
- for i,v in pairs(texts) do
- parts=split(v,'[\n]+')
- lines[c]=i..":"
- c=c+1
- for i1,v1 in pairs(parts) do
- lines[c]=" "..v1
- c=c+1
- end
- end
- monitor.clear()
- monitor.setCursorPos(1,1)
- for i=0,c-1 do
- monitor.setCursorPos(1,1+i)
- monitor.write(lines[i])
- end
- end
- function split(str, pat)
- local t = {} -- NOTE: use {n = 0} in Lua-5.0
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- while true do
- id,msg,distance,protocol=rednet.receive("monitoring")
- if msg:sub(1,len("textToMonitor:"))=="textToMonitor:" then
- msg=msg:sub(len("textToMonitor:")+1)
- ind=string.find(msg,":")
- monName=msg:sub(1,ind-1)
- if monName==mName then
- msg=msg:sub(ind+1)
- ind=string.find(msg,":")
- sName=msg:sub(1,ind-1)
- txt=msg:sub(ind+1)
- texts[sName]=txt
- rewrite()
- end
- else
- print("unknown message: '"..msg.."'")
- end
- --"textToMonitor:"..mName..":EnergyStored:"..storage.getEnergyStored().."/"..storage.getMaxEnergyStored()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement