peripheral.getNames

From ComputerCraft Wiki
Jump to: navigation, search


Grid Redstone.png  Function peripheral.getNames
Provides a list of all peripherals available.

If a device is located directly next to the system, then its name will be listed as the side it is attached to. If a device is attached via a Wired Modem, then it'll be reported according to its name on the wired network.

For example, if you have a wired modem on the left of a computer, and a monitor attached to that, then the first peripheral returned will be "left" (the wired modem) and the second will be along the lines of "monitor_x" (the monitor).
Syntax peripheral.getNames()
Returns A numerically indexed table of all peripherals present.
Part of ComputerCraft
API peripheral

Examples

Grid paper.png  Example
Prints a list of all attached peripherals, along with their type (using peripheral.getType()).
Code
local periList = peripheral.getNames()

for i = 1, #periList do
	print("I have a "..peripheral.getType(periList[i]).." attached as \""..periList[i].."\".")
end
Output Depending on the peripherals available, along the lines of:

I have a modem attached as "left".
I have a monitor attached as "monitor_0".
I have a turtle attached as "top".

etc...