Advertisement
dadragon84

Get Device

Feb 27th, 2025
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.89 KB | None | 0 0
  1. function getDeviceSide(device)
  2.     dSide = nil
  3.    
  4.     local dName = device
  5.     if dName == "monitor" then
  6.         dName = "monitor"
  7.     elseif dName == "modem" then
  8.         dname = "modem"
  9.     else
  10.         error("No Device Named: " .. device)
  11.     end
  12.  
  13.     -- Determine where device is.
  14.    
  15.     print("Looking for device,")
  16.     if peripheral.isPresent("left") and peripheral.getType("left")==dName then
  17.       dSide = "left"
  18.     elseif peripheral.isPresent("right") and peripheral.getType("right")==dName then
  19.       dSide = "right"
  20.     elseif peripheral.isPresent("top") and peripheral.getType("top")==dName then
  21.       dSide = "top"
  22.     elseif peripheral.isPresent("back") and peripheral.getType("back")==dName then
  23.       dSide = "back"
  24.     elseif peripheral.isPresent("bottom") and peripheral.getType("bottom")==dName then
  25.       dSide = "bottom"
  26.     else
  27.       print("No " .. device )
  28.       return
  29.     end
  30.     print(dName .. " found on "..dSide)
  31.     return dSide
  32.        
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement