Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tableColorsToSiphon={white="tilesiphon_1",orange="tilesiphon_2",magenta="tilesiphon_3",lightBlue="tilesiphon_4",yellow="tilesiphon_5"}
- local colors ={}
- for k,v in pairs(tableColorsToSiphon) do table.insert(colors,k) end
- --write(textutils.serialize(colors))
- function getColoredSiphon(color)
- return peripheral.wrap(tableColorsToSiphon[color])
- end
- function getAspect(color)
- local siphon=getColoredSiphon(color)
- local rawresults=siphon.getAspects()
- if (rawresults[1]==nil)then
- return nil
- else
- return rawresults[1]["name"]
- end
- end
- function getAspectAmount(color)
- local siphon=getColoredSiphon(color)
- local rawresults=siphon.getAspects()
- if (rawresults[1]==nil) then
- return nil
- else
- return rawresults[1]["quantity"]
- end
- end
- function isStable(color)
- local value1=getAspectAmount(color)
- if(value1==nil) then
- return false
- end
- os.sleep(0.85)
- if(getAspectAmount(color)==value1) then
- return true
- else
- return false
- end
- end
- function openNetwork()
- rednet.open("front")
- end
- function filtredWaitingMessage(time,filtre)
- openNetwork()
- local timer=os.startTimer(time)
- local continue=true
- while (continue) do
- local event,param1,message=os.pullEvent()
- if(event=="rednet_message") then
- if(message==filtre) then
- return param1, message
- end
- elseif(event=="timer") then
- if(param1==timer) then
- return nil, nil
- end
- end
- end
- 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 runProvider()
- openNetwork()
- while(true)do
- for k, v in pairs(colors) do
- write(" "..v)
- if(isStable(v))then
- write(" is stable\n")
- rednet.broadcast("wherestore-"..getAspect(v).."-"..getAspectAmount(v))
- local senderId, message=filtredWaitingMessage(0.2,"here")
- if (message=="here") then
- rednet.send(senderId,"store-"..getAspect(v))
- rednet.broadcast("open-"..v)
- while(getAspectAmount(v)~=nil) do
- os.sleep(0.05)
- end
- rednet.broadcast("close-"..v)
- os.sleep(0.15)
- rednet.send(senderId,"stop")
- end
- end
- end
- end
- end
- setStartup()
- runProvider()
- --local senderId, message=filtredWaitingMessage(20,"here")
- --write(textutils.serialize(message))
- --write(textutils.serialize(isStable("white")))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement