fi5hii

Untitled

Jun 10th, 2024
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. -- Define the function to find a specific peripheral
  2. function findPeripheral(targetPeripheral)
  3. -- Get a list of all peripheral names
  4. local peripherals = peripheral.getNames()
  5.  
  6. -- Iterate through the list of peripherals
  7. for _, name in ipairs(peripherals) do
  8. -- Check if the current peripheral matches the target peripheral
  9. if name == targetPeripheral then
  10. -- Return the peripheral if found
  11. return peripheral.wrap(name)
  12. end
  13. end
  14.  
  15. -- Return nil if the peripheral was not found
  16. return nil
  17. end
  18.  
  19. -- Example usage: finding the ae2cc_adapter_0 peripheral
  20. local ae2cc_adapter = findPeripheral("ae2cc_adapter_0")
  21.  
  22. if ae2cc_adapter then
  23. print("Peripheral ae2cc_adapter_0 found!")
  24. -- You can now interact with the ae2cc_adapter peripheral
  25. else
  26. print("Peripheral ae2cc_adapter_0 not found.")
  27. end
  28.  
Advertisement
Add Comment
Please, Sign In to add comment