Zatilla7

Auto Peripheral

Nov 29th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. function getDeviceSide(deviceType)
  2. deviceType = deviceType:lower()
  3.  
  4. for i, side in pairs(rs.getSides()) do
  5. if (peripheral.isPresent(side)) then
  6. if (string.lower(peripheral.getType(side)) == deviceType) then
  7. return side;
  8. end
  9. end
  10. end
  11.  
  12. return nil;
  13. end
  14.  
  15. function wrapThis(thing, f)
  16. local wrapped = nil
  17. while wrapped == nil and f <= 100 do
  18. wrapped = peripheral.wrap(thing.."_"..f)
  19. f = f + 1
  20. end
  21.  
  22. if wrapped == nil then
  23. side = getDeviceSide(thing)
  24. if side ~= nil then
  25. return peripheral.wrap(side)
  26. else
  27. return nil
  28. end
  29. else
  30. return wrapped
  31. end
  32. end
Advertisement
Add Comment
Please, Sign In to add comment