Sayomie550

Reactor Control 1.lua

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