Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function findPeripheral(_type, errMsg, callback)
- callback = type(callback) == "function" and callback or function() return true end
- local results = {}
- for _,name in pairs(peripheral.getNames()) do
- if peripheral.getType(name) == _type then
- local periph = peripheral.wrap(name)
- if callback(name, periph) then
- results[#results+1] = periph
- end
- end
- end
- if #results > 0 then
- return unpack(results)
- end
- error(errMsg or "Cannot find ".._type.." attached to this computer", 0)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement