Advertisement
temposabel

getmodems

Dec 14th, 2021 (edited)
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.69 KB | None | 0 0
  1. function getmodems(mode)
  2.   mode = mode or "default"
  3.  
  4.   if mode == "default" then
  5.     allp = peripheral.getNames()
  6.     d = {}
  7.     x = 0
  8.     for i,value in ipairs(allp) do
  9.       c = peripheral.getType(value)
  10.       if c == "modem" then
  11.         c = peripheral.wrap(value)
  12.         x = x + 1
  13.         d[x] = c
  14.       end
  15.     end
  16.     d["a"] = x
  17.     d["amount"] = x
  18.     return d
  19.   elseif mode == "sides" or mode =="s" then
  20.     allp = peripheral.getNames()
  21.     d = {}
  22.     x = 0
  23.     for i,value in ipairs(allp) do
  24.       c = peripheral.getType(value)
  25.       if c == "modem" then
  26.         x = x + 1
  27.         d[x] = value
  28.       end
  29.     end
  30.     d["a"] = x
  31.     d["amount"] = x
  32.     return d
  33.   end
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement