I will assume the readers of this tutorial know the basics of attaching a peripheral to a computer. Nevertheless, I will cover it briefly here
Spoiler
When encountering an unknown peripheral, the first thing to do is to list the methods available. Sometimes these can be displayed on screen, other times there are too many.
I would first try to show the methods on screen,
local methods = peripheral.getMethods( "top" ) --#note: for the purpose of this tutorial, I will always assume the peripheral
--#is on the top. If your peripheral is placed elsewhere, you may have to change
--#some of the arguments
for k, v in pairs( methods ) do --#iterate through the methods available to the peripheral
print( v ) --#print them to the screen
end
If this does not work, I would save them to a file which you can then peruse using the 'edit' program.
local methods = peripheral.getMethods( "top" ) local file = fs.open( "output", "w" ) --#opens a file named 'output' in write mode for k, v in pairs( methods ) do file.writeLine( v ) --#writes the method to a new line end file.close() --#closes the file (important!)
After running this program, you should use the built-in edit program on the file 'output',
>edit output
Once you have a list of the methods available, there are a few options. If one of the functions sounds as if it might do what you want the peripheral to do, you should try calling it. If it throws an error, it probably requires some sort of argument. For many methods available through Open Peripheral, you can try suppying "unknown". At this point, if you are still stuck, you should consult online or in-game documentation. OpenPeripheral documentation is in game, however I quite like this program.
As you are testing the methods, if they have return values, there are a few ways to handle it. This program will handle almost anything, but might not be so pretty:
local somePeripheral = peripheral.wrap( 'top' ) --#once again, note that I assume the peripheral is on top of the computer
function getInfo( ... )
local tValues = {...}
for k, v in pairs( tValues ) do
print( k .. type( v ) )
end
end
getInfo( somePeripheral.someMethod() )
If you're still frustrated after trying all the things in this tutorial, Ask A Pro is the best place to go. Please do not ask peripheral-specific questions in this thread, although questions about the tutorial are acceptable.
When posting in AAP, please remember to post the peripheral's mod's version, the minecraft version, and the CC version. It is also helpful to post if the mod provides the methods directly, or if a third party (such as OpenPeripheral) does. If you aren't sure, post your full mod list.
Edited by KingofGamesYami, 26 May 2016 - 10:54 PM.











