Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor=nil
- function setMonitor()
- monitor=peripheral.wrap("top")
- end
- function openNetwork()
- rednet.open("left")
- end
- function split(str, pat)
- local t={}
- 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
- function setStartup()
- if(fs.exists("startup")==false) then
- local startupFile=fs.open("startup","w")
- startupFile.write("os.run({}, \""..shell.getRunningProgram().."\")")
- startupFile.close()
- end
- end
- function __genOrderedIndex(t)
- local orderedIndex={}
- for key,value in pairs(t) do
- table.insert(orderedIndex,key)
- end
- table.sort(orderedIndex)
- return orderedIndex
- end
- function orderedNext(t,state)
- if state==nil then
- t.__orderedIndex=__genOrderedIndex(t)
- key=t.__orderedIndex[1]
- --write(textutils.serialize(t.__orderedIndex))
- return key, t[key]
- end
- key=nil
- for i=1,table.getn(t.__orderedIndex) do
- if t.__orderedIndex[i]==state then
- key= t.__orderedIndex[i+1]
- end
- end
- if key then
- return key, t[key]
- end
- t.__orderedIndex=nil
- return
- end
- function orderedPairs(t)
- return orderedNext, t, nil
- end
- function runMonitor()
- openNetwork()
- setMonitor()
- while true do
- local tableAspect={Free=0}
- rednet.broadcast("howmany")
- local timer=os.startTimer(0.2)
- local continue=true
- while continue do
- local event,param1,message=os.pullEvent()
- if (event=="rednet_message") then
- local messageTable=split(message,"-")
- --write(textutils.serialize(messageTable))
- if (messageTable[1]=="aspectdata") then
- if(messageTable[2]=="untyped") then
- tableAspect["Free"]=tableAspect["Free"]+1
- else
- if(tableAspect[messageTable[2]]==nil) then
- tableAspect[messageTable[2]]=messageTable[3]
- else
- tableAspect[messageTable[2]]=tableAspect[messageTable[2]]+messageTable[3]
- end
- end
- end
- elseif(event=="timer") then
- if(timer==param1) then
- continue=false
- end
- end
- end
- --write(textutils.serialize(tableAspect))
- local x,y=monitor.getSize()
- table.sort(tableAspect)
- monitor.clear()
- local i=1
- for k, v in orderedPairs(tableAspect) do
- --my issue is here
- monitor.setCursorPos(1,i)
- --write(" "..k.." x"..v) --this works fine
- monitor.write(k.." x"..v)-- this dont works
- i=i+1
- end
- os.sleep(5)
- end
- end
- setStartup()
- runMonitor()
- --write(textutils.serialize(split("test-1","-")))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement