tjaccardi

ChestAPI_0_2

Feb 23rd, 2020 (edited)
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. function initialize()
  2. _G.component = require("component")
  3. _G.sides = require("sides")
  4. _G.chestAccess = component.inventory_controller
  5. _G.transposer = component.transposer
  6.  
  7.  
  8.  
  9.  
  10. version = 0.2
  11.  
  12.  
  13.  
  14. --Notes from chummy:
  15. --[[ -----------------------------------------------------------
  16.  
  17. If you are editing variables in the global scope
  18. (Variables which are not local inside of your function,
  19. or above it), use _G. It means GLOBAL.
  20.  
  21. If you wanted to make it so component/sides/chestAccess/transposer
  22. are local, you can make this function return them, like so:
  23.  
  24. --return component, sides, chestAccess, transposer
  25.  
  26. Note that you would have to remove _G from the declarations.
  27.  
  28. I suggest searching "Variable Scoping In LUA"
  29.  
  30. ]] -------------------------------------------------------------
  31. end
  32.  
  33. function information()
  34. print("Version number: "..tostring(version))
  35. print("REQUIRES A TRANSPOSER AND AN INVENTORY CONTROLLER")
  36. print("All functions return 0 if there is no inventory unless otherwise documented.")
  37. print("Available functions:")
  38. print("inventoryScanner(side) - returns the inventory of inventory on given side.")
  39. print("getMaxSize(side) - gives the maxiumum size of the inventory.")
  40. print("---------------------------------------------------------------------------------------------------------------------------------------------------")
  41. print("Feel free to PM StormWolf with any functions you want added, they are mostly added on a per needed basis.")
  42. end
  43.  
  44. function isValid(side)
  45. if not chestAccess.getInventorySize(side) then
  46. return false
  47. elseif chestAccess.getInventorySize(side) then
  48. return true
  49. end
  50. return 0
  51. end
  52.  
  53.  
  54. function inventoryScanner(side)
  55. if not chestAccess.getInventorySize(side) then return 0 end
  56. size = chestAccess.getInventorySize(side)
  57. i = 1
  58. while i<size do
  59. item = chestAccess.getStackInSlot(side, i)
  60. if isValid(side)==false then break end
  61. inventory[i] = tostring(item.label)
  62. i=i+1
  63. end
  64. return inventory
  65. end
  66.  
  67. function getMaxSize(side)
  68. if isValid(side)==false then return 0 end
  69. size = chestAccess.getInventorySize(side)
  70. return size
  71. end
  72.  
  73. return {
  74. initialize,
  75. isValid,
  76. inventoryScanner,
  77. getMaxSize,
  78. transferItem
  79. }
Add Comment
Please, Sign In to add comment