Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- * actually, no need of wrapping up the sorter,
- -- it'll fire the isort_item event anyways
- -- * and I'll be using peripheral.call for .sort
- -- local sorter = peripheral.wrap("bottom") -- * you can uncomment this if you want
- local itemList
- local function saveItemList()
- local handle = fs.open("itemList", "w")
- handle.write(textutils.serialize(itemList))
- handle.close()
- end
- local function loadItemList()
- if not fs.exists("itemList") then
- itemList = {} -- * default value
- saveItemList()
- end
- local handle = fs.open("itemList", "r")
- itemList = textutils.unserialize(handle.readAll())
- handle.close()
- end
- loadItemList()
- while true do
- local event, item, amount = os.pullEvent("isort_item")
- print("Got " .. tostring(amount) .. " pieces of item #" .. tostring(item) .. "!")
- table.insert(itemList, item)
- saveItemList()
- -- * the only method of the sorter we're using
- -- is .sort - why wrapping it up then?
- peripheral.call("bottom", "sort", 2)
- -- sorter.sort(2) -- * you can uncomment this if you want
- --[[ -- * I've put this into a comment block
- -- * to be honest, I don't see the point of this part;
- -- is this here only for the sake of debugging?
- for i = 1, 4 do print(itemList[i]) end
- --]] -- * you can uncomment this if you want
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement