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

Using Peripherals from Other Mods

Started by KingofGamesYami, 21 May 2016 - 04:11 PM
KingofGamesYami #1
Posted 21 May 2016 - 06:11 PM
This tutorial is not for using peripherals provided by computercraft, such as the printer, monitor, etc. This tutorial will not specifically target any particular peripheral. Instead, this tutorial will teach you how to identify and use any peripheral.

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
SpoilerIf the peripheral is physically in contact with the computer, it is considered 'attached'

If the peripheral is connected via networking cables, make sure the wired modem connected to the peripheral is red (note: the wired modem connected to the computer using the peripheral does not necessarily need to be turned on)

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 on 26 May 2016 - 09:54 PM
Dragon53535 #2
Posted 21 May 2016 - 06:56 PM
First spoiler is messed up, you used a instead of