Advertisement
LBPHacker

Sorter monitor for bigbaddevil6

Aug 25th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.37 KB | None | 0 0
  1. -- * actually, no need of wrapping up the sorter,
  2. --   it'll fire the isort_item event anyways
  3. -- * and I'll be using peripheral.call for .sort
  4. -- local sorter = peripheral.wrap("bottom") -- * you can uncomment this if you want
  5.  
  6. local itemList
  7.  
  8. local function saveItemList()
  9.     local handle = fs.open("itemList", "w")
  10.     handle.write(textutils.serialize(itemList))
  11.     handle.close()
  12. end
  13.  
  14. local function loadItemList()
  15.     if not fs.exists("itemList") then
  16.         itemList = {} -- * default value
  17.         saveItemList()
  18.     end
  19.     local handle = fs.open("itemList", "r")
  20.     itemList = textutils.unserialize(handle.readAll())
  21.     handle.close()
  22. end
  23.  
  24. loadItemList()
  25.  
  26. while true do
  27.     local event, item, amount = os.pullEvent("isort_item")
  28.     print("Got " .. tostring(amount) .. " pieces of item #" .. tostring(item) .. "!")
  29.     table.insert(itemList, item)
  30.     saveItemList()
  31.    
  32.     -- * the only method of the sorter we're using
  33.     --   is .sort - why wrapping it up then?
  34.     peripheral.call("bottom", "sort", 2)
  35.     -- sorter.sort(2) -- * you can uncomment this if you want
  36.    
  37.     --[[ -- * I've put this into a comment block
  38.     --      * to be honest, I don't see the point of this part;
  39.     --        is this here only for the sake of debugging?
  40.     for i = 1, 4 do print(itemList[i]) end
  41.     --]] -- * you can uncomment this if you want
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement