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

Find What A Peripheral Can Do

Started by mrgreaper, 24 November 2013 - 12:55 PM
mrgreaper #1
Posted 24 November 2013 - 01:55 PM
i was messing about trying to hook up icbm launchers and needed a way to quickly see what they can do.. so i wrote a program to find out, im a very novice lua person…like majorly novice so there may be better ways but i found it useful so i thought i would share it


local tArgs = {...}
per = tArgs[1]
for i,v in ipairs(peripheral.getMethods(per))
do print(i..". "..v)
end

usage, if the program is called detect, you would run "detect back" and it would output all that the peripheral at the back can do

or if you have connected the peripheral with lan cables (see here for a good guide on that by @Kingdaro) then "detect monitor_0" would show all for monitor_0 etc
kind-sir #2
Posted 24 December 2013 - 02:27 PM
The code can be compressed into one line without much issue.
for i,v in pairs(peripheral.getMethods(...)) do print (i..". "..v) end

Thanks for sharing!
Lyqyd #3
Posted 24 December 2013 - 03:12 PM
Or further, into:


textutils.tabulate(peripheral.getMethods(...))

Of course, the output will be slightly different.
kind-sir #4
Posted 24 December 2013 - 05:28 PM
Or further, into:
 textutils.tabulate(peripheral.getMethods(...)) 
Of course, the output will be slightly different.

True, but you'd have more overhead for the textutils api (assuming that you do not load the library in with CraftOS, i.e. coroutine override)
It looks very nice, though!