Advertisement
superkh

peripherals API

Jun 6th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.01 KB | None | 0 0
  1. --This API is designed for easy to use peripherals
  2.  
  3. local peripherals = {}
  4. local function getPeripherals()
  5.     peripherals = {}
  6.     for _ , side in pairs( rs.getSides() ) do  
  7.         if peripheral.isPresent(side) then
  8.             local _ = {side, peripheral.getType(side)}
  9.             table.insert(peripherals, _)
  10.         end
  11.     end
  12. end
  13.  
  14. function returnPeripherals()
  15.     return peripherals
  16. end
  17.  
  18. local monitors = {}
  19. local function getMonitors()
  20.     monitors = {}
  21.     for key, value in pairs(peripherals) do
  22.         if value[2] == "monitor" then
  23.             local monitor = peripheral.wrap(value[1])
  24.             local Color = monitor.isColor()
  25.             local SizeX, SizeY = monitor.getSize()
  26.             local Side = value[1]
  27.             local _ = {monitor, Color, SizeX, SizeY}
  28.             table.insert(monitors, _)
  29.         end
  30.     end
  31. end
  32.  
  33. function returnMonitors()
  34.     return monitors
  35. end
  36.  
  37. function loadMoniter(side)
  38.     for key, value in pairs(monitors) do
  39.         if value[2] == side then
  40.             return monitors[key]
  41.         end
  42.         return nil
  43.     end
  44. end
  45.  
  46. function reloadPeriperals()
  47.     getPeripherals()
  48.     getMonitors()
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement