Advertisement
Guest User

Untitled

a guest
Aug 1st, 2015
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. local component = require("component")
  2. local sides = require("sides")
  3. local serialization = require("serialization")
  4.  
  5. itemTable = {}
  6. receivingModemAddress = "baf9bf02-7b0e-4b67-879e-8a6a6b71ff8a"
  7.  
  8. function checkCurrentChest()
  9. slot = 1
  10. while component.inventory_controller.getStackInSlot(sides.down, slot) ~= nil and slot < component.inventory_controller.getInventorySize(sides.down) do
  11. itemInfo = component.inventory_controller.getStackInSlot(sides.down, slot)
  12. myTable = {}
  13. myTable[itemInfo.label] = itemInfo.size
  14. for x,y in pairs(myTable) do print(x,y) end
  15. sendItemDataToComputer(serialization.serialize(myTable))
  16. slot = slot + 1
  17. end
  18. end
  19.  
  20. function addToTable(itemName, itemAmount) -- Adds an item/amount to the current item table.
  21. if itemTable[itemName] == nil then
  22. itemTable[itemName] = itemAmount
  23. else
  24. itemTable[itemName] = itemTable[itemName] + itemAmount
  25. end
  26. end
  27.  
  28. function sendItemDataToComputer(itemLabel)
  29. component.modem.send(receivingModemAddress, 888, itemLabel)
  30. end
  31.  
  32. function pairsByKeys (t, f) -- Sorts a table into alphabetical order.
  33. local a = {}
  34. for n in pairs(t) do table.insert(a, n) end
  35. table.sort(a, f)
  36. local i = 0 -- iterator variable
  37. local iter = function () -- iterator function
  38. i = i + 1
  39. if a[i] == nil then return nil
  40. else return a[i], t[a[i]]
  41. end
  42. end
  43. return iter
  44. end
  45.  
  46. function firstToUpper(str) -- Changes the first letter of the input string to uppercase.
  47. return (str:gsub("^%l", string.upper))
  48. end
  49.  
  50. checkCurrentChest()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement