This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
MudkipTheEpic's profile picture

[Solved] peripheral.getNames?

Started by MudkipTheEpic, 11 May 2013 - 12:42 PM
MudkipTheEpic #1
Posted 11 May 2013 - 02:42 PM
Does peripheral.getNames just use rs.getSides, then if it's a wired modem lists it's remote peripherals? I'm trying to sandbox it, so I need help.
Engineer #2
Posted 11 May 2013 - 02:48 PM
From the API section in your copy of CC/lua:

local native = peripheral

function getNames()
	local tResults = {}
	for n,sSide in ipairs( rs.getSides() ) do
		if native.isPresent( sSide ) then
			table.insert( tResults, sSide )
			if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then
				local tRemote = native.call( sSide, "getNamesRemote" )
				for n,sName in ipairs( tRemote ) do
					table.insert( tResults, sName )
				end
			end
		end
	end
	return tResults
end
Things you should know with figuring out this code:
- native.someFunc is a built-in function

I know for a matter of fact you can program so you can figure out the code :P/>
If not, just ask :)/>
MudkipTheEpic #3
Posted 11 May 2013 - 02:52 PM
That is the exact same thing I expected it to be, thanks for confirming.