Bottom: drive
Right: modem
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Peripheral Scanner
Started by tommyroyall, 20 February 2013 - 09:18 AMPosted 20 February 2013 - 10:18 AM
Peripheral Scanner
I have created a program of which will scan all 6 sides of your computer and then print what the peripheral types are. I encountered a need for this program when I was attempting to write something to find and register all modems and iron note blocks from Miscperiphals. I refined the program a little bit and decided that it is just good enough to be put up on the forums :)/>. I didn't put any screenshots up because all it does is print out whatever is there, so lets say you have a disk drive below and a modem on the right of your computer, this would be the output:
Posted 18 June 2013 - 02:57 AM
function getType(side)
if peripheral.isPresent(side) then
print(side..": "..peripheral.getType(side))
else
print(side..": none")
end
end
function getMethods(side)
if peripheral.isPresent(side) then
A = peripheral.getMethods(side)
if type(A) == "table" then
for i,v in ipairs(A) do print(v) end
elseif type(A) ~= "table" and A ~= nil then
print(A)
else
print("Error")
end
else
print("No peripheral to check on "..side)
end
end
this should improve it a bit
Posted 18 June 2013 - 08:56 AM
Just FYI you could do it In 3-5 lines…
for k, v in ipairs ({'top', 'bottom', 'left', 'right', 'front', 'back'}) do
print(v..": "..(peripheral.getType(v) or 'empty'))
end
Untested thoPosted 18 June 2013 - 09:20 AM
Just FYI you could do it In 3-5 lines…Untested thofor k, v in ipairs ({'top', 'bottom', 'left', 'right', 'front', 'back'}) do print(v..(peripheral.getType(v) or 'empty')) end
ya can even make it shorter:
for k, v in pairs (rs.getSides()) do
print(v..(peripheral.getType(v) or 'empty'))
end
Posted 18 June 2013 - 10:16 AM
Typed it using my tablet during break, sorry :P/>
Posted 18 June 2013 - 12:57 PM
me too :P/> but it works
Posted 18 June 2013 - 02:06 PM
Good! :-)