Advertisement
demon012

HopperMon

Sep 8th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.07 KB | None | 0 0
  1. HopperMon = {
  2.     hopper = peripheral.wrap("right"),
  3.     modem = rednet.open("top"),
  4.     sorterCompID = 5,
  5. }
  6.  
  7. function HopperMon:checkHopper()
  8.     local size = self.hopper.getSizeInventory()
  9.     size = size - 1 -- slot number starts at 0 so subtract 1
  10.  
  11.     for slot = 0, size do
  12.         local slotContents = self.hopper.getStackInSlot(slot)
  13.         if slotContents == nil then
  14.             return true
  15.         end
  16.     end
  17.  
  18.     return false
  19. end
  20.  
  21. function HopperMon:hasSpace()
  22.     local boolhasSpace = self:checkHopper()
  23.     local hasSpace = ""
  24.     if boolhasSpace then
  25.         print("has space")
  26.         hasSpace = "space"
  27.     else
  28.         print("has no space")
  29.         hasSpace = "noSpace"
  30.     end
  31.     local message = '' .. tostring(os.getComputerID()) .. ':' .. hasSpace
  32.     print("Sending " .. message)
  33.     rednet.send(self.sorterCompID, message)
  34. end
  35.  
  36. hm = HopperMon
  37.  
  38. while true do
  39.     event, param1, param2, param3 = os.pullEvent()
  40.     if event == 'rednet_message' then -- number senderid, string message, number distance
  41.         if param1 == hm.sorterCompID then
  42.             print(param2)
  43.             if param2:find('hasSpace') then
  44.                 hm:hasSpace()
  45.             end
  46.         end
  47.     end
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement