Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- p = peripheral.wrap("back") -- Interactive sorter change side as needed.
- m = peripheral.wrap("left") -- Modem change side as needed.
- m.open(32036)
- -- Variables that you have to set.
- item = "glass" -- Item that is in your storage media.
- recycle = 2 -- 2 = North, 3 = South, 4 = West, 5 = East
- order = 1
- -- First start-up
- if fs.exists("itemlist") == false then
- h = fs.open("itemlist", "w")
- h.write("0")
- h.close()
- end
- if os.getComputerLabel() == nil then
- os.setComputerLabel("upper")
- end
- function split(str, delim, maxNb)
- if string.find(str, delim) == nil then
- return { str }
- end
- if maxNb == nil or maxNb < 1 then
- maxNb = 0
- end
- local result = {}
- local pat = "(.-)" ..delim.. "()"
- local nb = 0
- local lastPos
- for part, pos in string.gmatch(str, pat) do
- nb = nb + 1
- result[nb] = part
- lastPos = pos
- if nb == maxNb then
- break
- end
- end
- if nb ~= maxNb then
- result[nb + 1] = string.sub(str,lastPos)
- end
- return result
- end
- -- Retrieves number of items in storage.
- f = fs.open("itemlist", "r")
- count = f.readAll()
- count = tonumber(count)
- f.close()
- -- Adds to number of items in storage.
- function function3()
- f = fs.open("itemlist", "w")
- f.writeLine(tostring(count))
- f.close()
- end
- -- The function for sorting the item
- function function2()
- event, id, amount = os.pullEvent("isort_item")
- if count == 65535 then
- p.sort(recycle)
- else
- count = count + amount
- function3()
- p.sort(0)
- end
- end
- -- The function for updating the monitor.
- function function1()
- event, side, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- Table = {}
- Table = split(message, ":")
- computer = tonumber(Table[1])
- if replyChannel == 33880 and computer == order then
- m.transmit(33880, 32036, item..": "..tostring(count))
- elseif replyChannel == 49794 and Table[1] == item then
- message = tonumber(Table[2])
- if message > count then
- count = 0
- function3()
- print(count.." remaining")
- else
- count = count - message
- function3()
- print(count.." remaining")
- end
- end
- end
- -- Main running code.
- while true do
- parallel.waitForAny(function1, function2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement