Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define the function to find a specific peripheral
- function findPeripheral(targetPeripheral)
- -- Get a list of all peripheral names
- local peripherals = peripheral.getNames()
- -- Iterate through the list of peripherals
- for _, name in ipairs(peripherals) do
- -- Check if the current peripheral matches the target peripheral
- if name == targetPeripheral then
- -- Return the peripheral if found
- return peripheral.wrap(name)
- end
- end
- -- Return nil if the peripheral was not found
- return nil
- end
- -- Example usage: finding the ae2cc_adapter_0 peripheral
- local ae2cc_adapter = findPeripheral("ae2cc_adapter_0")
- if ae2cc_adapter then
- print("Peripheral ae2cc_adapter_0 found!")
- -- You can now interact with the ae2cc_adapter peripheral
- else
- print("Peripheral ae2cc_adapter_0 not found.")
- end
Advertisement
Add Comment
Please, Sign In to add comment