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

Find API

Started by roger109z, 05 April 2016 - 12:24 AM
roger109z #1
Posted 05 April 2016 - 02:24 AM
This API is intended to find peripherals!


Pastebin code: wpA73N2E

Functions:

find.modem()
-finds any modem attached to your computer (returns the side string)

find.computer()
-finds any computer on the notwork or attacked to the computer (returns all computers table)


find.mon()
-finds any monitor connected to the network (returns all monitors table)

todo
-add filters for advanced monitors/computers
-add disks and printers
-add filters for checking if a modem is wireless
Edited on 05 April 2016 - 12:28 AM
Anavrins #2
Posted 05 April 2016 - 03:09 AM
So, is this the same as peripheral.find?
roger109z #3
Posted 06 April 2016 - 03:35 AM
no peripheral.find wraps the first peripheral it finds this returns all of the peripherals and can be used for rednet.
Anavrins #4
Posted 06 April 2016 - 03:38 AM
peripheral.find does returns all peripherals…
With modem1, modem2, modem3 = peripheral.find("modem") or modems = { peripheral.find("modem") }
Additionally, it takes a filter function, peripheral.find("modem", function(side, obj) return obj.isWireless() end) to only get wireless modems, (return not obj.isWireless()) for only wired ones.
Similar thing with monitors using obj.isColor().
Edited on 06 April 2016 - 01:57 AM
roger109z #5
Posted 11 April 2016 - 04:12 AM
but peripheral.find WRAPS a modem
this returns the side so it can be used with rednet :P/>
Anavrins #6
Posted 11 April 2016 - 05:21 AM
peripheral.find("modem", function(side) rednet.open(side) end) would achieve the same thing.
Bomb Bloke #7
Posted 11 April 2016 - 11:07 AM
Truth be told, peripheral.find("modem", rednet.open) would be more efficient again. Though I believe that one was pointed out to me in a similar fashion…

Suffice to say, while peripheral.find() is a great function with uses that aren't immediately obvious, this API may still be useful for a user who doesn't have it - there are a variety of CC builds in use out there, and 1.6 or later is required for peripheral.find().
DannySMc #8
Posted 28 May 2016 - 11:24 PM
I swear this is the code I gave you on slack… -__-