Advertisement
NolanSyKinsley

Untitled

Apr 3rd, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. local function getDevices(deviceType)
  2. local deviceName = nil
  3. local deviceIndex = 1
  4. local deviceList, deviceNames = {}, {} -- Empty array, which grows as we need
  5. local peripheralList = peripheral.getNames() -- Get table of connected peripherals
  6.  
  7. deviceType = deviceType:lower() -- Make sure we're matching case here
  8.  
  9. for peripheralIndex = 1, #peripheralList do
  10. -- Log every device found
  11. -- printLog("Found "..peripheral.getType(peripheralList[peripheralIndex]).."["..peripheralIndex.."] attached as \""..peripheralList[peripheralIndex].."\".")
  12. if (string.lower(peripheral.getType(peripheralList[peripheralIndex])) == deviceType) then
  13. -- Log devices found which match deviceType and which device index we give them
  14. printLog("Found "..peripheral.getType(peripheralList[peripheralIndex]).."["..peripheralIndex.."] as index \"["..deviceIndex.."]\" attached as \""..peripheralList[peripheralIndex].."\".")
  15. deviceNames[deviceIndex] = peripheralList[peripheralIndex]
  16. deviceList[deviceIndex] = peripheral.wrap(peripheralList[peripheralIndex])
  17. deviceIndex = deviceIndex + 1
  18. end
  19. end -- for peripheralIndex = 1, #peripheralList do
  20.  
  21. return deviceList, deviceNames
  22. end -- function getDevices(deviceType)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement